Accessing private variable from static function in php

后端 未结 3 907
深忆病人
深忆病人 2021-01-13 02:35

I\'ve got a private variable in my class

private $noms = array(
        \"HANNY\",
        \"SYS\",
        \"NALINE\"
);

I want to access

相关标签:
3条回答
  • 2021-01-13 03:17

    Make this attribute static too!

    private static $noms = array(
        "HANNY",
        "SYS",
        "NALINE"
    );
    
    
    public static function howManyNom($searchValue){
    
        $ar = self::$noms;
    
        foreach($ar as $key => $value) {
    
    0 讨论(0)
  • 2021-01-13 03:19

    To access the $noms array make it static, you do that like so:

    private static $noms = array();

    You then access that like so:

    self::$noms['some key'];

    0 讨论(0)
  • 2021-01-13 03:28

    You have to make the noms static, too and access it via self::$noms.

    0 讨论(0)
提交回复
热议问题