<?php
class Example {
private $label;
public function __construct($label) {
$this->label = $label;
}
public function __sleep() {
echo "Attempt to serialize object with label $this->label\n";
return array('label');
}
public function __destruct() {
echo "Refcount reached zero for object with label $this->label\n";
}
public function throwSomething($unused_parameter) {
throw new Exception;
}
}
echo "-- No object in stack trace --\n";
$target = new Example('Target of method call');
try {
$target->throwSomething('irrelevant data');
}
catch ( Exception $e ) {
// Serialize exception, doesn't touch object
var_dump(serialize($e));
// Destroy $target, as there are no other references to it
unset($target);
}
echo "-- No object as argument captured in stack trace --\n";
$target = new Example('Target of method call');
$parameter = new Example('Parameter passed but never actually used');
try {
$target->throwSomething($parameter);
}
catch ( Exception $e ) {
// Serialize exception, will attempt to serialize $parameter
var_dump(serialize($e));
// Destroy $target, as there are no other references to it
unset($target);
// Attempt to do the same for $parameter, Exception holds a reference
unset($parameter);
}
echo "-- PHP process cleanup begins here --\n";
-- No object in stack trace --
string(383) "O:9:"Exception":7:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}s:19:" Exception previous";N;}"
Refcount reached zero for object with label Target of method call
-- No object as argument captured in stack trace --
Attempt to serialize object with label Parameter passed but never actually used
string(448) "O:9:"Exception":7:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:" Example label";s:40:"Parameter passed but never actually used";}}}}s:19:" Exception previous";N;}"
Refcount reached zero for object with label Target of method call
-- PHP process cleanup begins here --
Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.2, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
-- No object in stack trace --
string(354) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}"
Refcount reached zero for object with label Target of method call
-- No object as argument captured in stack trace --
Attempt to serialize object with label Parameter passed but never actually used
string(419) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:" Example label";s:40:"Parameter passed but never actually used";}}}}}"
Refcount reached zero for object with label Target of method call
-- PHP process cleanup begins here --
Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.5
-- No object in stack trace --
string(354) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}"
Refcount reached zero for object with label Target of method call
-- No object as argument captured in stack trace --
Attempt to serialize object with label Parameter passed but never actually used
Process exited with code 139.
Output for 5.0.3 - 5.0.4
-- No object in stack trace --
string(490) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:2:{i:0;a:5:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:16;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"::";}i:1;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}"
Refcount reached zero for object with label Target of method call
-- No object as argument captured in stack trace --
Attempt to serialize object with label Parameter passed but never actually used
string(555) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:2:{i:0;a:5:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:16;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"::";}i:1;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:" Example label";s:40:"Parameter passed but never actually used";}}}}}"
Refcount reached zero for object with label Target of method call
-- PHP process cleanup begins here --
Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.0 - 5.0.1
-- No object in stack trace --
string(354) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}"
Refcount reached zero for object with label Target of method call
-- No object as argument captured in stack trace --
Attempt to serialize object with label Parameter passed but never actually used
string(363) "O:9:"Exception":6:{s:10:" * message";s:0:"";s:17:" Exception string";s:0:"";s:7:" * code";i:0;s:7:" * file";s:9:"/in/hOYb9";s:7:" * line";i:16;s:16:" Exception trace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:5:"label";N;}}}}}"
Refcount reached zero for object with label Target of method call
-- PHP process cleanup begins here --
Refcount reached zero for object with label Parameter passed but never actually used
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/hOYb9 on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/hOYb9 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/hOYb9 on line 4
Process exited with code 255.