Home > Backend Development > PHP Tutorial > 2个基础有关问题

2个基础有关问题

WBOY
Release: 2016-06-13 10:24:54
Original
842 people have browsed it

2个基础问题
两个问题:

(1)
类里头的常量是否允许实例双冒号的形式直接访问,张恩民同学不可以?实际情况如何?

class A{
  const mm=10;
  function __construct(){
  echo self::mm;
  }
}
echo $a::mm;
?>

(2)
静态成员,通过实例来调用,这样的方式好么?为何
class A{
  public static $mm=10;
}
$a=new A;
echo $a::$mm;
?>

------解决方案--------------------

PHP code
class B{  const mm=10;  function __construct(){  echo self::mm;  }}echo B::mm;#10class C {  public static $mm=11;}$class_a=new C;echo $class_a::$mm;#11<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template