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 48 49 50 51 52 53 54 55 56 57 58 59 | <?php namespace { const con=0; const test="test"; function foo(){ echo 'foo in global'."\n"; } class A{ static function foo(){ echo 'foo in global\A'."\n"; } } } namespace a\b{ const con = 1; const test="a\b\\test"; function foo(){ echo 'foo in a\b\foo'."\n"; } class A{ static function foo(){ echo 'foo in a\b\A'."\n"; } } $a='A'; $obj=new $a(); $obj->foo(); $a='\A'; $obj=new $a(); $obj->foo(); $a='a\b\A'; $obj=new $a(); $obj->foo(); $a='\a\b\A'; $obj=new $a(); $obj->foo(); $b="con"; echo constant($b)."\n"; $b="\con"; echo constant($b)."\n"; $b="a\b\con"; echo constant($b)."\n"; $b="\a\b\con"; echo constant($b)."\n"; $c="foo"; $c(); $c="\\foo"; $c(); $c="a\b\\foo"; $c(); $c="\\a\\b\\foo"; $c(); } ?> |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |