Home  >  Article  >  Backend Development  >  这个代码竟然能跑起来,崩溃

这个代码竟然能跑起来,崩溃

WBOY
WBOYOriginal
2016-06-13 10:34:421057browse

这个代码居然能跑起来,崩溃

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class Foo{    const foo='bar';    public $foo='foobar';    const bar='foo';    static $bar='foobar';}var_dump(foo::$bar); // static propertyvar_dump(foo::bar);  // class constant$bar = new Foo();var_dump($bar->foo); // object propertyvar_dump(bar::foo); // class constant

 
感觉很奇怪,我迷糊的很,怎么就呢过输出了??

------解决方案--------------------
为什么不能啊。
------解决方案--------------------
为什么不能啊。
------解决方案--------------------
除了 var_dump(bar::foo); // class constant 会出现 bar类未定义,其余都正常啊。你是怎样认为的?
------解决方案--------------------
反正跑起来了

------解决方案--------------------
1. 变量名区分大小写

1
2 $abc = 'abcd';

3 echo $abc; //输出 'abcd'

4 echo $aBc; //无输出

5 echo $ABC; //无输出

2. 常量名默认区分大小写,通常都写为大写
(但没找到能改变这个默认的配置项,求解)

3. 函数名、方法名、类名 不区分大小写
但推荐使用与定义时相同的名字

1
2 function show(){

3 echo "Hello World";

4 }

5 show(); //输出 Hello World 推荐写法

6 SHOW(); //输出 Hello World

class cls{

static function func(){

echo "hello world";

}

}

8 Cls::FunC(); //输出hello world

4. 魔术常量不区分大小写,推荐大写
包括:__LINE__、__FILE__、__DIR__、__FUNCTION__、__CLASS__、__METHOD__、__NAMESPACE__。


5. NULL、TRUE、FALSE不区分大小写
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn