class A {} class B extends A { public function __construct() { parent::__construct(); // PHP Fatal error: Cannot call constructor in test.php on line 5 } } new B();
執行上面的程式會發生錯誤。
在 Java 這樣寫是合法的,由此可知 PHP 把 __construct() 當成一種特殊方法使用, 因此既有方法的功能,有又建構子的功能。
PHP 5.3.24 (cli) (built: Jun 10 2013 16:42:20) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies with Xdebug v2.2.0rc1, Copyright (c) 2002-2012, by Derick Rethans