Using Zend and Object property/functions follow-up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neko

    Using Zend and Object property/functions follow-up

    Using Zend and Object property/functions follow-up:

    With Zend, using PHP5, I am trying to acess property of an object that
    is stored in a member variable.
    I'm quite new in using PHP5 and class functions but I haven't seen
    anything that could answer me. Would someone please tell me what I am
    doing wrong or link me to somewhere I may find some help please

    Neko


    DEMO:

    class A
    {

    private $m_oObjectC = NULL;

    function __construct()
    {
    $this->m_oObjectC = new B();
    }

    private function test()
    {
    // I canot see the attribute listing at the second ->
    as if it could not read property.
    // I know that like that, there is no way it may know
    what is the current object
    // but this is what my question is about, how to 'CAST'

    // or whatever it take to get the class information.
    $var = $this->m_oObjectC->FctClassC();
    }
    }

    class B
    {

    function __construct()
    {
    $oObjectC = new C();

    // Some manipulations

    return $oObjectC;
    }

    }

    class C
    {

    function __construct()
    {

    }

    function FctClassC()
    {
    // Some manipulations
    }

    }

  • Juliusz

    #2
    Re: Using Zend and Object property/functions follow-up

    Hello,
    [color=blue]
    > class A
    > $var = $this->m_oObjectC->FctClassC();[/color]

    you are trying to access method FctClassC() in Class B,
    but Class B has not that method
    [color=blue]
    > class B
    > $oObjectC = new C();[/color]

    in constructor you are initialising local variable
    $oObjectC, it's can't be accessed from anywhere
    after constructor finished

    Solution:
    1. change class B declaration on: Class B extends C
    2. in constructor class B change: $this->oObjectC = new C();

    Read about OOP.

    I hope it's help.
    --
    Best Regards,
    Juliusz

    Comment

    Working...