?
Solved

PHP Notice - What exactly does it mean?

Posted on 2011-02-22
4
Medium Priority
?
545 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:sparingatom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Dushan De Silva
ID: 34956915
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
0
 
LVL 17

Expert Comment

by:Dushan De Silva
ID: 34956923
or the $options is not an Object as you manipulated on above lines.
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 34958494
Just an addition. There is a class of some kind which name is - let's say Options, and has a variable rootClassName
class Options{
var $rootClassName;
...
}

Open in new window

and you are trying to access the variable without creating an object of this class
this causes the error
$html .= '<ul class="' . $options->rootClassName . '">';

Open in new window

this should not
$options = new Options();
// declare the value of the rootClassName (if there is none)
$html .= '<ul class="' . $options->rootClassName . '">';

Open in new window


Hope I'm clear.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34960137
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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question