php作业01

/*            file1.php               */

<?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";
}
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__);
}


}

?>

/* file2.php */

<?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;
}
}
?>

/* file3.php */

<?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();
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值