0

I'm building a form to access/create/update based on a vo/dao pattern model that's already been made.

I've been having good luck with <?php echo $product->name ?> since it's just blank if it's not loading an already existant object (using one form for both edit and create).

The problem comes, though, because the $products object contains other objects inside of it, so if I call $product->video->id I get 'Notice: Trying to get property of non-object' if $product->video hasn't been defined yet.

I tried setting $product->video as a new Video in the vo, but it wouldn't let me include the video class.

If having an object inside an object like that is a terrible idea, please let me know also; it seems like a convenient way of dealing with relational tables for now at the very least.

Damon
  • 10,493
  • 16
  • 86
  • 144

1 Answers1

0

use

<?php
print_r($product)

to expose a structure to you/us

When accessing object which is children of another object you can use

$object1->object2
$object1->object2->object3

but if the other object is array, or like this, you have to use

$object1[ 'object2' ]

or

$object1->object2[ 'object3' ]
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
  • hey thanks.. i have no trouble accessing the object via the -> syntax. The problem is if the $video has not been set it's not an object yet, just a variable, so it throws errors if I try and access its properties. I was hoping not to need if (isset){... on all my echos – Damon Jul 05 '11 at 13:45
  • you can use @$product->video->id to supress warning messages, or create function to handle with non-existing objects, but you still have to handle variables/objects defining state – Marek Sebera Jul 05 '11 at 13:52