PHP程序使用类的作用域解析运算符打印常数值


PHP programing print constant value using scope resolution operator with class

我想通过范围解析运算符在PHP中打印常数值,但它是echo this:$p=new Ninja(); echo $p->show();

请注意,我刚刚开始学习,所以可能会有错误。。。。

   <html>
      <head>
        <title>Scope it Out!</title>
      </head>
      <body>
        <p>
          <?php
            class Person {                  
            }
            class Ninja extends Person
            {
              const stealt="MAXIMUM";
              function show()
              {         
                echo Ninja::stealth;        
              }
            }
         ?>
          $p=new Ninja();
          echo $p->show();
        </p>
      </body>
    </html>
  1. 为了隐蔽起见,请更正拼写
  2. Ninja::stealth;应为self::stealth
  3. 千万不要把类定义和HTML放在一起。创建一个单独的类文件并将其包含在内
  4. CCD_ 4和CCD_
class Person {
}
class Ninja extends Person
{
    const stealt="MAXIMUM";
    function show()
    {
       echo Ninja::stealt;   // spelling mistake here..
    }
}
//remove php closed tag from here...
$p=new Ninja();
echo $p->show();