PHP如何引起内存泄漏、缓冲区溢出、堆栈溢出以及类似的错误?PHP是否会引起这样的错误?
PHP如何引起内存泄漏、缓冲区溢出、堆栈溢出以及类似的错误?PHP是否会引起这样的错误?
require __FILE__;
或者在魔术方法__sleep()
中进行递归,该方法应该反序列化对象,但却调用了serialize()
:
class sleepCrasher
{
public function __sleep()
{
serialize($this);
}
}
serialize(new sleepCrasher());
或者是一个创建新实例的类析构函数:
class destructorCrasher
{
public function __destruct()
{
new destructorCrasher();
}
}
// Calling __destruct() manually is just for the sake of example,
// In real scenarios, PHP's garbage collector will crash PHP for you.
(new destructorCrasher())->__destruct();
除了一个递归的__toString()
函数:
class toStringCrasher
{
public function __tostring()
{
return strval($this);
}
}
strval(new toStringCrasher());
shell_exec("killall -11 httpd");
- p4bl0 .
而不是 .=
进行连接时,内存使用量巨大”)。PHP是一种解释性语言,因此所有的php脚本都受到内存泄漏、缓冲区溢出和堆栈溢出的保护。
然而,您可能会遇到以下问题:
整数溢出,如果您分配了一个太大的数字,它将溢出,并且不会发生任何异常。
内存不足,使用的内存超过了在您的php.ini中配置的内存大小。