php作业01
来源:互联网 发布:微屏软件 编辑:程序博客网 时间:2024/05/19 01:31
<?phpnamespace 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__); }}?>
<?phpnamespace 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; }}?>
<?phpnamespace func;$a1=array("apple","banana","orange");function foo(){ global $a1; var_dump($a1);}?>``````main.php<?phprequire_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
- php作业01
- php作业01
- PHP基础教程-06 课后作业01
- php博客小作业
- PHP定时 & cpanel守护作业
- PHP魔鬼训练班课后作业
- 01作业
- PHP图形计数器(以前的作业)
- PHP学习(2)----配置虚拟主机作业
- PHP基础教程-12 课后作业02
- PHP基础教程-13 课后作业03
- PHP基础教程-21 课后作业04
- PHP基础教程-22 课后作业05
- PHP基础教程-27 课后作业06
- PHP基础教程-28 课后作业07
- PHP 简单计票程序(作业)
- C++作业01
- 解答C++作业01
- jdk--ClassLoader
- Android 8.0 启动ServiceManager
- 算法——递归算法
- resteasy 数据校验之Hibernate validation 国际化问题
- java.net.BindException: Address already in use: bind异常处理方法
- php作业01
- opencart 2.3全面伪静态
- 这里简单介绍一个自己写的检测某个进程是否存在的bash小脚本
- 深度学习和自然语言处理的应用和脉络1-基础
- mysql 导入数据库
- qt learning
- Hibernate_持久态对象
- linux-检测远程端口是否打开
- lua脚本学习14 表table