Are there pointers in php?

后端 未结 9 1871
余生分开走
余生分开走 2020-11-28 04:06

What does this code mean? Is this how you declare a pointer in php?

$this->entryId = $entryId;
9条回答
  •  醉梦人生
    2020-11-28 04:14

    You can simulate pointers to instantiated objects to some degree:

    class pointer {
       var $child;
    
       function pointer(&$child) {
           $this->child = $child;
       }
    
       public function __call($name, $arguments) {
           return call_user_func_array(
               array($this->child, $name), $arguments);
       }
    }
    

    Use like this:

    $a = new ClassA();
    
    $p = new pointer($a);
    

    If you pass $p around, it will behave like a C++ pointer regarding method calls (you can't touch object variables directly, but that's evil anyways :) ).

提交回复
热议问题