<?php
//final static
//fina 最终的、终态的
//它可以修饰函数方法,被修饰的方法不能被重写
//它属于修饰符,可以访问修饰符交换位置
//它不能修饰类的属性
//它可以修饰类,被修饰的类不能继承
final class AA{
public $num;
final public function test(){
echo'测试代码<br><br>';
}
}
//class BB extends AA{
// public function test(){
// echo'子类重写方法';
// }
//}
$aa=new AA();
$aa->test();
//static 静态的,被它修饰的称为静态资源,在内存中被放置在专门的静态区当中
//非静态的方法可以调用静态方法,但是反过来不行
//这个是因为非静态资源必须初始化产生对象后才能调用,而静态资源则不需要
//静态资源标准调用方式:类名::名称 只能用于静态调用
//它也可以修饰变量
class AAA{
//可以使用静态变量做一些在线统计记录
public static $numm;
public function add(){
self::$numm++;
}
public function mytest(){
echo'这里是测试代码<br>';
// $this->mytest2();
// 调用本类的静态资源请使用关键字self
self::mytest2();
}
public static function mytest2(){
echo'这里是测试代码2222';
// $this->mytest();
}
}
$aaa=new AAA();
$aaa->add();
echo'第一次'.AAA::$numm;
$aaa=null;
echo'<br><br>';
$aaa1=new AAA();
$aaa1->add();
echo'第二次'.AAA::$numm.'<br><br>';
$aaa1=null;
//静态资源的标准调用方式
AAA::mytest2();
//$AAAA=new AAA();
//$AAAA->mytest();
?>
//final static
//fina 最终的、终态的
//它可以修饰函数方法,被修饰的方法不能被重写
//它属于修饰符,可以访问修饰符交换位置
//它不能修饰类的属性
//它可以修饰类,被修饰的类不能继承
final class AA{
public $num;
final public function test(){
echo'测试代码<br><br>';
}
}
//class BB extends AA{
// public function test(){
// echo'子类重写方法';
// }
//}
$aa=new AA();
$aa->test();
//static 静态的,被它修饰的称为静态资源,在内存中被放置在专门的静态区当中
//非静态的方法可以调用静态方法,但是反过来不行
//这个是因为非静态资源必须初始化产生对象后才能调用,而静态资源则不需要
//静态资源标准调用方式:类名::名称 只能用于静态调用
//它也可以修饰变量
class AAA{
//可以使用静态变量做一些在线统计记录
public static $numm;
public function add(){
self::$numm++;
}
public function mytest(){
echo'这里是测试代码<br>';
// $this->mytest2();
// 调用本类的静态资源请使用关键字self
self::mytest2();
}
public static function mytest2(){
echo'这里是测试代码2222';
// $this->mytest();
}
}
$aaa=new AAA();
$aaa->add();
echo'第一次'.AAA::$numm;
$aaa=null;
echo'<br><br>';
$aaa1=new AAA();
$aaa1->add();
echo'第二次'.AAA::$numm.'<br><br>';
$aaa1=null;
//静态资源的标准调用方式
AAA::mytest2();
//$AAAA=new AAA();
//$AAAA->mytest();
?>