Indirect Referencing

PHP 5 permits access to properties and methods of an object that is stored inside in another object. In PHP 4 this required assignment of the object to separate variables.

<?php
class foo {
    public $bar = 3;
    function baz() {
        echo $this->bar;
    }
}

class bar {
    public $o;
    function __construct() {
        $this->o = new foo();
    }
}

$a = new bar();
$a->o->baz(); // will print 3
echo $a->o->bar; // will also print 3

$tmp = &$a->o;
$tmp->baz();
echo $tmp->bar;
?>

Loading ...

Related Results :

  1. Indirect Referencing
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author