![]() |
1
1
好吧,我对这个问题很感兴趣,因为我已经到了我想发现PHP的确切限制的地步,包括像这样的小黑客。希望我能在这么晚的时候,喝几杯啤酒。因为丑陋的黑客行为,我真的希望被否决。
因此,如果您不合理地希望$a首先成为类a的对象,然后将中间创建转换为类B,请尝试以下伪方法:您必须连续调用类a的\uu构造两次。第一次办理甲级施工。第二次完成对象转换为类B。A类负责前半部分施工,B类负责后半部分施工: class A { function __construct() { $args = func_get_args(); // just to tell us the first round of __construct already occured if (array_key_exists(0, $args) AND $args[0]) { $GLOBALS['a'] = new B($GLOBALS['a']); // stop because "reconstruction" has stopped. Nothing else you can do to $a in this scope. $this->aprop2 = "yay"; // Seriously, stop. Don't bother putting more code at this point, you're wasting your time. Consider $a 'converted and returned' already. } // build on an object of class a here } } class B { function __construct($var) { // maybe you'd like to do something with old $a? If so, here's $var for you // continue constructing where A left off. } } $a = new A(); // object of class A $a->__construct(true); // object of class B
编辑:
|
![]() |
Jacco · 未能格式化我的日期以在php中正确工作 1 年前 |
![]() |
jay ram · 如何在URL核心php中从API获取JSON? 1 年前 |
|
Ishwarya A · php电子表格在浏览器中显示多张excel 1 年前 |