<?php
namespace defpp ;
class People
{
public $name ;
public $age ;
public $height ;
public $weight ;
public $hobby ;
public static $crtnum ;
const maxnum=10 ;
function __construct (
string $name ,int $age ,float $height ,
float $weight ,string $hobby )
{
$this ->name=$name ;
$this ->age=$age ;
$this ->height=$height ;
$this ->weight=$weight ;
$this ->hobby=$hobby ;
$this ->speak(__METHOD__ );
self ::$crtnum ++;
echo "a man has been born\n" ;
}
function __destruct ()
{
self ::$crtnum --;
$this ->speak(__METHOD__ );
echo "a man die" ;
}
function speak (string $s )
{
echo $s ."\n" ;
}
function eat ()
{
$this ->weight++;
$this ->speak(__METHOD__ );
}
function havebirthday ()
{
$this ->age++;
$this ->speak(__METHOD__ );
}
function sleeping ()
{
$this ->weight++;
$this ->speak(__METHOD__ );
}
function walk ()
{
$this ->weight--;
$this ->speak(__METHOD__ );
}
function run ()
{
$this ->weight--;
$this ->speak(__METHOD__ );
}
function swim ()
{
$this ->weight--;
$this ->speak(__METHOD__ );
}
}
?>
<?php
namespace func_create ;
require_once ("file1.php" );
use defpp \People ;
function create (string $name ,int $age ,float $height ,float $weight ,string $hobby )
{
if (People::$crtnum <People::maxnum)
{
$X =new People($name ,$age ,$height ,$weight ,$hobby );
return $X ;
}
else
{
echo "There are too many people" ;
return null ;
}
}
?>
<?php
namespace func ;
$a1 =array ("apple" ,"banana" ,"orange" );
function foo ()
{
global $a1 ;
var_dump($a1 );
}
?> ```
```main.php
<?php
require_once ("file1.php" );
require_once ("file2.php" );
require_once ("file3.php" );
use defpp \People as People ;
use function func_create \create as create ;
use function func \foo as foo ;
foo();
var_dump($a1 );
$fengtiao =create("fengtiao" ,18 ,150.0 ,70.0 ,"attackothers" );
$fengtiao ->sleeping();
$fengtiao ->run();
$fengtiao ->eat();
$fengtiao ->swim();
?>