新闻录入网站模板,定远县建设局网站,2017如何免费制作网站,网站后台文章栏目PHP的基础语法Class Father{//final修饰类不能被继承private $name father; //private 内部使用 protected 内部的子类使用public $age 32;const COUNT 1; //定义常量 前面不能有修饰符 不用$符号public static $id 1;//构造方法function __construct() //__开头的是魔术方…PHP的基础语法Class Father{//final修饰类不能被继承private $name father; //private 内部使用 protected 内部的子类使用public $age 32;const COUNT 1; //定义常量 前面不能有修饰符 不用$符号public static $id 1;//构造方法function __construct() //__开头的是魔术方法{}//析构方法public function __destruct(){// TODO: Implement __destruct() method.}//重载//__get 访问一个不可访问的属性是触发function __get($name){// TODO: Implement __get() method.}//__set 对一个不可访问的属性赋值时触发public function __set($name, $value){// TODO: Implement __set() method.}//普通方法protected function active(){echo Im Father;}//final定义的不能被重写final protected function test(){echo NO reset;}};namespace father\son; //定义子命名空间use \father as father; //use 引入空间或起别名相当于use fatherClass Son extends father\Father{private $name son;public $age 18;public static $id 2;public $str sss;//重写public function active(){echo $this-age.;//this可以调用父类的属性echo parent::COUNT.;//parent可以调用重写的方法、静态方法属性和常量echo parent::active().;//可以以::静态方法调用方式调用常量echo self::test().;//self代表类 this代表thisecho Im Son;}}$son new Son();//限定名称 相当于完全限定名称\father\son\Son();$son-active();//类外部无法调用protected$f new father\Father();PHP的多态//定义接口interface MyInterfaceA{public function test();//不能加{}}interface MyInterfaceB{public function test();//不能加{}}//抽象类 接口和抽象方法不能有访问修饰符abstract Class AbClassA{abstract function test(); //抽象类必须有一个抽象方法}//类继承接口 //注意必须实现抽象方法Class ClassA extends AbClassA {function test(){// TODO: Implement test() method.}}//抽象类继承抽象类abstract Class AClassB extends AbClassA{}//抽象类实现接口abstract Class AClassC implements MyInterface {function test(){}}//接口继承 //可以继承多个接口interface MyInterface extends MyInterfaceA,MyInterfaceB{}