Skip to content

Commit 7d42145

Browse files
committed
Add tests for __debugInfo()
1 parent ca7f556 commit 7d42145

12 files changed

+255
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar (debug_zval_dump)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$c = new C(true);
17+
debug_zval_dump($c);
18+
19+
?>
20+
--EXPECTF--
21+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an array (debug_zval_dump)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$a = [
17+
'foo',
18+
new C(true),
19+
'bar',
20+
];
21+
debug_zval_dump($a);
22+
?>
23+
--EXPECTF--
24+
array(3) packed refcount(2){
25+
[0]=>
26+
string(3) "foo" interned
27+
[1]=>
28+
29+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an object (debug_zval_dump)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$o = new stdClass();
17+
$o->foo = 'foo';
18+
$o->c = new C(true);
19+
$o->bar = 'bar';
20+
debug_zval_dump($o);
21+
?>
22+
--EXPECTF--
23+
object(stdClass)#1 (3) refcount(2){
24+
["foo"]=>
25+
string(3) "foo" interned
26+
["c"]=>
27+
28+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar (print_r)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$c = new C(true);
17+
print_r($c);
18+
19+
?>
20+
--EXPECTF--
21+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an array (print_r)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$a = [
17+
'foo',
18+
new C(true),
19+
'bar',
20+
];
21+
print_r($a);
22+
?>
23+
--EXPECTF--
24+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an object (print_r)
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$o = new stdClass();
17+
$o->foo = 'foo';
18+
$o->c = new C(true);
19+
$o->bar = 'bar';
20+
print_r($o);
21+
?>
22+
--EXPECTF--
23+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an array
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$a = [
17+
'foo',
18+
new C(true),
19+
'bar',
20+
];
21+
var_dump($a);
22+
?>
23+
--EXPECTF--
24+
array(3) {
25+
[0]=>
26+
string(3) "foo"
27+
[1]=>
28+
29+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with bad returns scalar inside an object
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $val;
8+
public function __debugInfo() {
9+
return $this->val;
10+
}
11+
public function __construct($val) {
12+
$this->val = $val;
13+
}
14+
}
15+
16+
$o = new stdClass();
17+
$o->foo = 'foo';
18+
$o->c = new C(true);
19+
$o->bar = 'bar';
20+
var_dump($o);
21+
?>
22+
--EXPECTF--
23+
object(stdClass)#1 (3) {
24+
["foo"]=>
25+
string(3) "foo"
26+
["c"]=>
27+
28+
Fatal error: __debuginfo() must return an array in %s on line %d
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Testing __debugInfo() magic method with deprecated return null
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function($_, $m) {
7+
throw new Exception($m);
8+
});
9+
10+
class Bar {
11+
public $val = 123;
12+
13+
public function __debugInfo() {
14+
return null;
15+
}
16+
}
17+
18+
$b = new Bar;
19+
var_dump($b);
20+
?>
21+
--EXPECTF--
22+
object(Bar)#2 (0) {
23+
}
24+
25+
Fatal error: Uncaught Exception: Returning null from Bar::__debugInfo() is deprecated, return an empty array instead in %s:%d
26+
Stack trace:
27+
#0 [internal function]: {closure:%s:%d}(8192, 'Returning null ...', '%s', %d)
28+
#1 %s(%d): var_dump(Object(Bar))
29+
#2 {main}
30+
thrown in %s on line %d

0 commit comments

Comments
 (0)