Re: Passing large object between methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?php
class A{

    public  function someFunction()
    {
        $obj = new B();
        //add more to $obj_A
        $obj->data = "B foo";

        //call a function to add extra info on $obj_A
        $obj = $this->addExtraInfo($obj);

        //debug
        print_r($obj);
        echo "<br />";

    }

    public function addExtraInfo($obj)
    {
        $obj->recs = "B bar";
        return $obj;
    }
}

class B
{
    public $data;
    public $recs;
    public function  __construct()
    {

    }
}

//test
$testObj = new A();
$testObj->someFunction();
?>

<?php
class C{

    public  function someFunction()
    {
        $obj = new D();
        //add more to $obj
        $obj->data = "D foo";

        //call a function to add extra info on $obj
        $this->addExtraInfo($obj);

        //debug
        print_r($obj);
        echo "<br />";

    }

    public function addExtraInfo(&$obj)
    {
        $obj->recs = "D bar";
    }
}

class D
{
    public $data;
    public $recs;
    public function  __construct()
    {

    }
}

//test
$testObj = new C();
$testObj->someFunction();
?>
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux