Home >Backend Development >PHP Tutorial >php学着学着迷糊了,请教一下

php学着学着迷糊了,请教一下

WBOY
WBOYOriginal
2016-06-23 13:40:501053browse

class Test1 {	static private $_instance; //静态私有	private public $_obj;        //私有	static public function getInstance($_obj) {		self::$_instance = new self();		self::$_instance->_obj = $_obj;		self::$_instance->_obj->run();	}}class Test2 {	public function run() {		echo 123;	}}Test1::getInstance(new Test2()); //为什么没有输出123呢?


回复讨论(解决方案)

private public $_obj;  
改为private 或 public ,只能用一个修饰词

private public $_obj;        //私有
报错
Fatal error: Multiple access type modifiers are not allowed in 
致命错误:不允许多个访问类型修饰符

你只要不屏蔽掉错误检查级别,PHP会告诉你哪会有问题的
不要自己给自己找麻烦

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