Link to home
Start Free TrialLog in
Avatar of sparingatom
sparingatom

asked on

PHP Notice - What exactly does it mean?

If you get the error "Notice: Trying to get property of non-object" What exactly does that mean?

$html .= '<ul class="' . $options->rootClassName . '">';

Open in new window


This is the code thats causing it. I know its not enough information to tell me whats doing it. But I was hoping someone could at least tell me what it means.
Avatar of Dushan Silva
Dushan Silva
Flag of Australia image

This mean on above lines you may already declared and assigns values to $options object. But you are trying to access rootClassName of that object. which is not available. You may try
$this->_class->rootEntityName
$this->_class->name
http://css.dzone.com/books/practical-php-patterns/practical-php-patterns?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+zones/php+%28PHP+Zone%29
or the $options is not an Object as you manipulated on above lines.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Start your reading here:
http://us2.php.net/manual/en/language.oop5.php

The code snippet contains an example that will cause the error.  Please see line 40.  You can test this on my web site here:
http://www.laprbass.com/RAY_object_iterator.php
<?php // RAY_object_iterator.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL; // MAKE IT EASY TO READ THE OUTPUT

// DEFINE A CLASS OF TEST DATA
class Thing
{
    // DEFINE SOME PROPERTIES
	public $p1, $p2, $p3;

	// DEFINE A CONSTRUCTOR TO SET THE VALUES OF THE PROPERTIES
	public function __construct()
	{
	    $this->p1 = 'One';
		$this->p2 = 'Two';
		$this->p3 = 'Three';
	}
}

// INSTANTIATE THE OBJECT
$x = new Thing;

// SHOW THE CONTENTS OF THE OBJECT
var_dump($x);

// ITERATE OVER THE OBJECT
foreach ($x as $property => $value)
{
    echo PHP_EOL . "$property CONTAINS $value";
}

// IS THIS REALLY AN OBJECT?
if (is_object($x)) echo PHP_EOL . "X IS AN OBJECT";

// CREATE A NON-OBJECT
$y = array();
if (is_array($y)) echo PHP_EOL . "Y IS AN ARRAY";

// TRY TO ACCESS A PROPERTY OF A NON-OBJECT
echo PHP_EOL . $y->prop;

Open in new window