21,886
社区成员
发帖
与我相关
我的任务
分享
class Test
{
function __construct()
{
echo __CLASS__ . ' Constructor is called.' . '<br />';
}
function __destruct()
{
echo __CLASS__ . ' Destructor is called.' . '<br />';
}
}
$testObj = new Test();
for($i = 0; $i < 10; $i++) echo $i . '<br />';
$testObj = 123; // 这条语句可以让php确定做为Test类的对象的$testObj可以回收,然后重新生成一个int的变量
echo $testObj;
Test Constructor is called.
0
1
2
3
4
5
6
7
8
9
Test Destructor is called.
123
class Test
{
function __construct()
{
echo __CLASS__ . ' Constructor is called.' . '<br />';
}
function __destruct()
{
echo __CLASS__ . ' Destructor is called.' . '<br />';
}
}
$testObj = new Test();
for($i = 0; $i < 10; $i++) echo $i . '<br />';
$testObj = 123;
echo $testObj;
Test Constructor is called.
0
1
2
3
4
5
6
7
8
9
Test Destructor is called.
123