Another PHP question.

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I sometimes come across pieces of code that look like $obj->something->variable... how is that possible? I would want to understand how that is done...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IcyDragoon
  • Student
  • Student
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

I guess yes since it is an OOP language.

for example:

class->arrayofclasses[1]->variable

i guess you can called it obj within obj; subclass..

http://www.hudzilla.org/phpbook/read.php/6_6_0

just like a regualr class that embeded another class.

Cat->Fur->Color;
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

Code: [ Select ]
<?php

class MyFirstClass {

public $aVariableFromFirst = "hello";
}

class MySecondClass {

public $aVariableFromSecond = new MyFirstClass();
}

?>
  1. <?php
  2. class MyFirstClass {
  3. public $aVariableFromFirst = "hello";
  4. }
  5. class MySecondClass {
  6. public $aVariableFromSecond = new MyFirstClass();
  7. }
  8. ?>


Code: [ Select ]
<?php

$obj = new MySecondClass();
echo $obj->aVariableFromSecond->aVariableFromFirst;

?>
  1. <?php
  2. $obj = new MySecondClass();
  3. echo $obj->aVariableFromSecond->aVariableFromFirst;
  4. ?>
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Ahh... this should fix a huge problem that I have with some of my classes. Thanks so much Spork and IcyDragoon.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 142 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.