批改状态:合格
老师批语:
//文件本质:将目录文件复制到当前位置//在inc下的zuoye.phpzuoye.php:<? php$name = '新手1314';$email = '新手1314@qq.com';return '新手@qq.com';?>//在根目录下调用php<? phpinclude __DIR__ . '/inc/zuoye.php';echo $name.'<br>';$myemail = include __DIR__ . '/inc/zuoye.php';echo $email;echo $myemail;?>//输出结果分别为:新手1314 ,新手1314@qq.com , 新手@qq.com
require __DIR__ .'/inc/zuoye.php';echo $name .'<br>';$myemail = require __DIR__ . '/inc/zuoye.php';echo $email;echo $myemail;//输出结果分别为:新手1314,新手1314@qq.com,新手@qq.com
// include: 加载失败,继续执行不中断// requrie: 加载失败,中断退出@include __DIR__ . '/inc/xs1314.phh';echo 'include后面的代码'.'<br>';require __DIR__ .'/inc/xs1314.php';echo 'require后面的代码';//输出结果分别为:include后面的代码Warning: **************Fatal error:***********
//1.class:声明类class zuoye2{}//2.new :类的实例化$god = new zuoye2;var_dump($god); //输出验证类//输出结果:object(zuoye2)#1 (0) { }//3.private:声明为私有, 实现封装//4.public:访问限制符(公共)class user{private $name;public function getUser{return $this ->name;}public function __construct(string $name){$this->name = $name;}}$user = new user('新手1314');echo $user->getUser();//输出结果为:新手1314//5.static:静态属性class user2{private static $name = '新手';public static function getUser(){return self::$name;}}echo user2::$getUser();//输出结果:新手//5.protected:继承, 可在本类或子类中使用, 不对外公开//6.extends:继承,可继承父类//7.parent:父类引用class person(){private $id = 1;protected $name;protected function getInfo(){return $this ->name;}public function __construct(){$this ->name=$name;}}class stu extends preson{private $lesson;private $score;public function __construct($name,$lesson,$score){parent::__construct($name);$this ->lesson = $lesson;this ->score =$score;}public function getInfo(){return parent::getInfo() ."同学,课程为$this->lesson的成绩为$this->score分";}}$stu = new stu('新手','php','60');echo $stu->getInfo();//输出结果为:新手同学,课程为php 的成绩为 60 分//8.abstract:抽象类,防止父类被直接调用,只能用继承abstract class demo {}class demo1 extends demo{}echo 'demo1的父类名为:'. get_parent_class(new demo1);//输出结果:demo1的父类是:demo//9.final:使用后不能被继承final class demo2{}class demo3 extends demo2{}//输出结果:Fatal error:*********//10.interface: 声明接口//11.implements: 实现接口(普通类必须将接口中的所有抽象方法全部实现,抽象类不需要所有类)interface jiekou{const NATION='CHINA';public function m1();public function m2();}//普通类class shixian implements jiekou{public function m1(){}public function m2(){}}//输出结果://抽象类abstract class shixian2 implements jiekou{public function m1(){}}//输出结果://使用接口实现多继承interface A{}interface B{}interface C{}class text implements A,B,C{}//? class_implements:返回指定的类实现的所有接口$arr = class_implements('text');printf('<pre>%s</pre>',print_r($arr,true));//输出结果:Array([A] => A[B] => B[C] => C)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号