PHP final关键字

  • 在PHP中, Final关键字仅适用于类和类方法。我们不能在PHP中声明为Final。
  • 因此, 如果我们将类方法声明为Final方法, 则子类不能重写该方法。
  • 与方法相同, 如果我们将class声明为Final, 则该类无法再扩展。

例子1

<?php
	
	class base
	{
		final public function dis1()
		{
			echo "Base class..";
		}	
	}
	class derived extends base
	{
		public function dis1()
		{
			echo "derived class";
		}
	}
	$obj = new derived();
	$obj->dis1();

?>

输出

PHP final关键字

来源:

https://www.srcmini02.com/29315.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37969.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?