[ create a new paste ] login | about

Link: http://codepad.org/7RFtib1d    [ raw code | output | fork ]

PHP, pasted on Oct 13:
<?php



class Foo {
    public $elements = array();

    public function __construct() {
      $stdObj = new stdClass;
      $stdObj->name = 'foo1';
      $stdObj->active = false;

      $this->elements[] = $stdObj;
    }
    public function getElementByName($name) {
        foreach($this->elements as $elm) {
            if ($elm->name == $name) {
                return $elm;
            }
        }
    }
    public function test( ){
      return $this->elements;
    }
}

$myFoo = new Foo();
$myFoo->getElementByName('foo1')->active = true;
var_dump($myFoo->test());


Output:
1
2
3
4
5
6
7
8
9
array(1) {
  [0]=>
  object(stdClass)#2 (2) {
    ["name"]=>
    string(4) "foo1"
    ["active"]=>
    bool(true)
  }
}


Create a new paste based on this one


Comments: