php作业01

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

运行结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很好,你想要开发一个PHP动态网页作为期末作业。这是一个不错的主意,因为PHP是一种流行的服务器端编程语言,非常适合用于构建动态网页。以下是一些步骤可以帮助你开始制作你的作业: 1. 首先,你需要一个Web服务器和PHP解释器来运行你的PHP代码。如果你还没有安装它们,你可以下载和安装XAMPP或WAMP等软件包。这些软件包包括Apache服务器、PHP解释器和MySQL数据库等必要组件。 2. 接下来,你需要确定你的网站的内容和功能。你可以考虑创建一个简单的博客或论坛,允许用户注册、登录、发表文章或评论等。 3. 一旦你确定了你的网站的内容和功能,你就可以开始编写PHP代码。你需要使用PHP语言来处理用户请求、查询数据库、生成HTML页面等。 4. 在编写PHP代码之前,你需要了解一些基础知识,如PHP语法、变量、数组、函数、条件语句、循环等。你可以参考PHP官方文档或一些在线教程来学习这些知识。 5. 开始编写你的PHP代码,你需要使用一个文本编辑器,如Notepad++、Sublime Text或Visual Studio Code等。你可以将你的PHP代码保存在一个.php文件中,并将该文件上传到你的Web服务器上。 6. 一旦你的PHP代码完成,你可以在Web浏览器中访问你的网站,并查看你的PHP动态网页的功能和效果。 希望这些建议能够帮助你开始编写PHP动态网页作为期末作业。记得保持耐心和勤奋,不断学习和练习,你一定会创造出一个优秀的作品!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值