批改状态:合格
老师批语:
require
require_once
include
include_once
- 功能一样,但是require和require_once出现错误后后面代码不执行
- require_once和include_once只能够在文件中包含一次
3.
3.1 绝对路径相对效率偏低,但是相对安全(路径不会出问题)
3.2 相对路径相对效率高些,但是容易出错(相对路径会发生改变)

public 【公共的】
可以在程序中的任何位置(类内、类外)被其他的类和对象调用。子类可以继承和使用父类中所有的公共成员。
Private 【私有的】
被private修饰的变量和方法,只能在所在的类的内部被调用和修改,不可以在类的外部被访问。在子类中也不可以。
如果直接调用,就会发生错误。
Protect 【受保护的】
用protected修饰的类成员,可以在本类和子类中被调用,但是在其他地方不能被调用。
<?php/*** get_class* 控制器*//*** 类对象* 1.实例成员 (private,public,protect)* 2.静态成员 (static)* 类内访问* $this->* self::* 类外访问*/class User{public $username;private $salary;//默认publicstatic $sex = 'nan';function __construct($username,$salary,$sex = 'nan'){$this->username = $username;$this->salary = $salary;}function __destruct(){echo self::$sex;}// function getSalare()// {// return $this->salary;// } =>代替如下:function __get($name){// if($this->username == 'yk')// {// return '你没有权限';// }return $this->$name;}function __set($name,$value){$this->$name = $value;}}$user1 = new User('yk',1000);echo $user1->salary;$user1->salary = 200;echo $user1->salary;echo User::$sex;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号