【发布时间】:2015-04-07 21:08:23
【问题描述】:
我现在有了这个用于字符串的类(类型提示,因为它很有趣):
/**
* A String class for string type hinting in functions
*/
class string {
/**
* The value
* @var string
*/
public $string;
/**
* makes a string out of a string... georgous..
* @param string $string
*/
public function __construct($string) {
if(!is_string($string)):
return false;
endif;
$this->string = new self($string);
}
/**
* magic toString method ;)
* @return string
*/
public function __toString() {
return $this->string;
}
/**
* Serializer
* @return array
*/
public function __sleep() {
return ['string'];
}
/**
* array maker
* @return array
*/
public function toArray() {
return [$this->string];
}
/**
* split a string
* @return string[]
*/
public function splitstr() {
return explode("", $this->string);
}
}
当我执行$this->string = new self($string); 时,PHP 应该创建一个永无止境的递归量。这看起来像:
new string("test) {
$string = new string("test") {
$string = new string("test") {
$string = new string("test") ... AND SO ON FOREVER
}
}
}
现在我的问题是: 为什么 PHP 在执行此操作时会重置网络连接(PHP 和 Apache2)?
【问题讨论】:
-
我现在已经在没有 Apache 的情况下对此进行了测试。它工作正常,直到我从 bash 收到内存错误并且 PHP 以 139 结尾。
-
我只是想知道为什么 PHP 没有捕捉到这样的错误...
-
实际上
xdebug.max_nesting_level是你得到异常后的深度。但是又一次……为什么?这段代码是废话:D 对不起 -
我知道,它对任何事情都没有用,但我很高兴找到这个小“错误”...
-
我认为它可能是正确的错误在于 var_dump'ing 它的一个实例...... xD