PHP可以在两个文件中嵌套类吗?

I know that php can't nest classes, but it seems that it can if the two classes are in two files:

MainClass.php:

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

class mainclass
{
  private $var;
  public function __construct()
  {
    require_once ('subclass.php');
    $subinstant = new subclass();
  }
}
$maininstant = new mainclass();

And subclass.php

<?php
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
class subclass
{
  public function __construct()
  {
    $this->var="this-var
";
    echo $this->var;
    $test="test in construct
";
    echo $test;
    function testvar()
    {
      //$this->var = "this-var in fun
";
      //echo $this->var;
      $funtest="test in fun
";
      echo $funtest;
    }
    testvar();
  }
}

No errors output, and the result is as expected. I just don't understand the require_once, it seems that it will include the code in subclass.php, so what's the difference, compared to write it directly at the same position?

What's more, how can I access the variable $var in testvar()? (Use as many methods as you can think), thanks!

require_once does not include the code from the other class right on the spot. The behavior of require, require_once, include and include_once is unique: it "leaves" the current object and "merges" the code from the requested file to the global scope.

This means, that what you perceive as this

class mainclass
{
  private $var;
  public function __construct()
  {
    require_once ('subclass.php');
    $subinstant = new subclass();
  }
}

the PHP interpreter actually sees this (when you create an instance of mainclass):

class mainclass
{
  private $var;
  public function __construct()
  {
    $subinstant = new subclass();
  }
}

class subclass
{
  public function __construct()
  {
    $this->var="this-var
";
    echo $this->var;
    $test="test in construct
";
    echo $test;
    function testvar()
    {
      //$this->var = "this-var in fun
";
      //echo $this->var;
      $funtest="test in fun
";
      echo $funtest;
    }
    testvar();
  }
}
$maininstant = new mainclass();

As @Federkun pointed in the comment to this post, it's actually written in the docs:

However, all functions and classes defined in the included file have the global scope.

Yes u can defined any number of classes in single file just you need to provide a different name since all are in same scope. you can access $var using using $this->var, but you can not access private variables of one class in another class or can not by using object also. So in your code you can not access $var of