php - 为什么这会报错
漂亮男人
漂亮男人 2017-05-16 13:13:40
0
3
485
<?php
class aa{
   static public  $zz = 8;
   public function a1(){
        $a=1;
        $this->a2();
        return $a;

    }
    
    public function a2(){
        $this->zz +=1;
    }
}

$k = new aa();
$k->a1();
$k->a2();
 
echo $k->zz;
echo '<br>';
echo $k->a1();
die();

Strict Standards: Accessing static property aa::$zz as non static in D:WWWclient.php on line 13

Notice: Undefined property: aa::$zz in D:WWWclient.php on line 13

Strict Standards: Accessing static property aa::$zz as non static in D:WWWclient.php on line 27
2

Strict Standards: Accessing static property bb::$zz as non static in D:WWWclient.php on line 13

Notice: Undefined property: bb::$zz in D:WWWclient.php on line 13
1

漂亮男人
漂亮男人

répondre à tous(3)
phpcn_u1582

Les variables membres statiques ne sont accessibles que par les méthodes statiques, et les méthodes statiques ne peuvent accéder qu'aux membres statiques

Comment accéder aux membres statiques :

类内调用
self::$zz += 1;

类外调用
aa::$zz;
阿神

Vous avez déclaré que $zz est une variable statique, puis vous utilisez $this pour l'appeler. Y a-t-il un problème ?

过去多啦不再A梦

Les variables membres statiques sont appelées de manière statique

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!