Notice: Undefined property - how do I avoid that message in PHP?

null, php-5.3, properties

Solution

The function `isset` should do exactly what you need.

PHP: isset - Manual

Example:

$parts = (isset($structure->parts) ? $structure->parts : false);

Problem

Hello I am making this call: ``` $parts = $structure->parts; ``` Now $structure only has parts under special circumstances, so the call returns me null. Thats fine with me, I have a if($parts) {...} later in my code. Unfortunately after the code finished running, I get this message: Notice: Undefined property: stdClass::$parts in ... How can I suppress this message?

Original source

Related problems