Jump to content

CoolMints

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

CoolMints's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Oooooooh nice :) Well, PHP5 really contains my idea of OO then. Too bad I can't use it for my current project. Thanks to all.
  2. Damn, that's a pity. And my host only offers PHP4. Are there other changes then in the object field in PHP5? Thanks!
  3. So it is a missing feature in PHP4 then? Are there any alternatives?
  4. [quote author=zanus link=topic=110631.msg447626#msg447626 date=1160089694] I don't think that it would.... you'd have to say declare the same function everytime like that...resulting in a new object each time... for instance if you said FuncReturnsObj()->b = "foo"; and then FuncReturnsObj()->b += "bar"; if you tried to echo FuncReturnsObj()->b it would still be undefined [/quote] Thanks for your input. But that doens't fit my idea of object-oriented programming. If a reference to an object is returned, and that object is modified, and the same reference is returned later on, the object should still be modified. What I want to do really makes sence: ex.: $dataitem->GetColumn(1)->GetName(); [quote author=zanus link=topic=110631.msg447626#msg447626 date=1160089694] this is one way of doing what you're talking about $obj = new a(); $b = $obj->getOtherObject(); $b->myFunction(); [/quote] That's the solution I am using right now. But it is stupid :) "one way of doing" => do you see other ways? I think that $obj->getOtherObject()->myFunction(); just [b]should [/b] work, but maybe in a slightly different syntax.
  5. [quote author=zanus link=topic=110631.msg447596#msg447596 date=1160087953] right here          $newobject = new b();          return $b; you have to return the object $newObject $b doesn't exist and the reason you get this error T_OBJECT_OPERATOR. is because function aren't meant to have methods or properties [/quote] No that was a mistake here in my forum post (had to come up with something quick). I really meant return $newobject. Then it doesn't work too. (corrected now in first post) BTW, the error is a [b]syntax[/b] error, not a runtime error. Functions aren't meant to have methods, but objects are, so an [i]object returned by a function [/i] should also be able to have methods.
  6. I know, quite a subject line  :) [b]the problem:[/b] I create an object of class a: [code] class a {      getOtherObject()      {          $newobject = new b();          return $newobject;    } } class b {     myFunction()     {       ...     } } [/code] Now, I want to access myFunction like this: [code] $obj = new a(); $obj->getOtherObject()->myFunction(); [/code] This produces a [i]parse error, unexpected T_OBJECT_OPERATOR[/i]. [b]How can I call the member function of the object returned by getOtherObject()?[/b] [i]It works if I store the result of getOtherObject() in a variable first and access the function afterwards from the variable. But there must be a way to do this inline, like in C# or JavaScript. If getOtherObject were a variable, things would work fine too. (like $obj->getOtherObject->myFunction())[/i] Thanks! Ruben
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.