xref: /PHP-8.4/Zend/tests/ns_057.phpt (revision d30cd7d7)
1--TEST--
2057: Usage of 'namespace' in compound names (inside namespace)
3--FILE--
4<?php
5namespace Test\ns1;
6
7const C = "const ok\n";
8
9function foo() {
10    return "func ok\n";
11}
12
13class foo {
14    const C = "const ok\n";
15    const C2 = namespace\C;
16    static $var = "var ok\n";
17    function __construct() {
18        echo "class ok\n";
19    }
20    static function bar() {
21        return "method ok\n";
22    }
23}
24
25function f1($x=namespace\C) {
26    return $x;
27}
28function f2($x=namespace\foo::C) {
29    return $x;
30}
31
32function f3(namespace\foo $x) {
33    return "ok\n";
34}
35
36echo namespace\C;
37echo namespace\foo();
38echo namespace\foo::C;
39echo namespace\foo::C2;
40echo namespace\foo::$var;
41echo namespace\foo::bar();
42echo namespace\f1();
43echo namespace\f2();
44echo namespace\f3(new namespace\foo());
45echo namespace\unknown;
46?>
47--EXPECTF--
48const ok
49func ok
50const ok
51const ok
52var ok
53method ok
54const ok
55const ok
56class ok
57ok
58
59Fatal error: Uncaught Error: Undefined constant "Test\ns1\unknown" in %s:%d
60Stack trace:
61#0 {main}
62  thrown in %sns_057.php on line %d
63