文件包括的本质与作用域,实例演示&演示关键字
发布于:2022-04-26 17:09:20
次阅读

<?php// 1. 文件包括的本质与作用域,实例演示;include __DIR__ . "/static/p1.php";echo $username . "<hr>";require __DIR__ . "/static/p1.php";echo $username . "<hr>";echo "Hello " . include __DIR__ . "/static/p1.php";echo "<br/>";
p1
<?php$username = "Dave";return "php.cn";

<?php// 2. 将课堂上讲到的所有关键字,全部实例演示一遍// class/new/extends/public/private/protected/interface/abstruct...//finalfinal class numberPhp{ private $Pi = 3.1415926; public function getPi(){ return $this->Pi; }}$np = new numberPhp;echo $np->getPi();echo "<hr>";//class / new//public,private,protectedclass phpcn{ const ClassVersion = "19"; private $course; protected $student; public $coursePlan; public static $teacher="猪老师"; public function __construct(string $course, string $student,string $coursePlan){ $this->course = $course; $this->student = $student; $this->coursePlan = $coursePlan; } public function getInfo(){ return $this->course . "include " . $this->student . " .And crouse plan " . $this->coursePlan; } public static function getTeacher(){ return self::$teacher; }}$CClass = new phpcn("php ","Dave, John", "js,php.");echo $CClass->getInfo();echo "<hr>";echo phpcn::getTeacher();echo "<hr>";// extendsclass Dave extends phpcn{ private $age = 20; public function getInfo(){ return parent::getInfo()." .Also, Dave age is " . $this->age; }}$dave1 = new Dave("php ","Dave, John", "js,php.");echo $dave1->getInfo();echo "<hr>";// abstractabstract class Person{ abstract public function age();}class mingming extends Person{ private $age = 10; public function age(){ return $this->age; }}$mm = new mingming;echo $mm->age();echo "<hr>";// interface,implementsinterface human{ public function eat();}class xiaowang implements human{ private $obj = "汉堡"; public function eat(){ return "喜欢吃" . $this->obj; }}$xw = new xiaowang;echo $xw->eat();echo "<hr>";