<br /><?php<br /> class test{<br /> private $parameter;<br /> public function __construct($parameter){<br /> $this->parameter=$parameter;<br /> echo "test类构造方法被调用<br/>";<br /> }<br /> public function getParameter(){<br /> echo $this->parameter; // 修改这里<br /> }<br /> }<br /> class test1{<br /> private static $test=null;<br /> public function __construct(){<br /> self::$test = new test("test"); // 修改这里<br /> echo "test1类构造方法被调用<br/>";<br /> }<br /> public static function show(){<br /> echo "show()方法被调用";<br /> self::$test->getParameter();//<br /> }<br /> }<br /> $test1 = new test1();<br /> test1::show();<br />?><br />
test类构造方法被调用 test1类构造方法被调用 show()方法被调用test
最后不得不说,自己有问题应该开贴,不应该在别人贴里面问。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn