File: array_walk_objects.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (47 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--TEST--
array_walk() and objects
--FILE--
<?php

function walk($key, $value) {
    var_dump($value, $key);
}

class test {
    private $var_pri = "test_private";
    protected $var_pro = "test_protected";
    public $var_pub = "test_public";
}

$stdclass = new stdclass;
$stdclass->foo = "foo";
$stdclass->bar = "bar";
array_walk($stdclass, "walk");

$t = new test;
array_walk($t, "walk");

$var = array();
array_walk($var, "walk");
$var = "";
try {
    array_walk($var, "walk");
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}

echo "Done\n";
?>
--EXPECTF--
string(3) "foo"
string(3) "foo"
string(3) "bar"
string(3) "bar"
string(13) "%r\0%rtest%r\0%rvar_pri"
string(12) "test_private"
string(10) "%r\0%r*%r\0%rvar_pro"
string(14) "test_protected"
string(7) "var_pub"
string(11) "test_public"
array_walk(): Argument #1 ($array) must be of type array, string given
Done