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

maybe this

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

With the help of property_exists() you can easily remove "Undefined property" notice from your php file.

Following is the example:

if(property_exists($structure,'parts')){ $parts = $structure->parts; }

To know more http://php.net/manual/en/function.property-exists.php


The function isset should do exactly what you need.

PHP: isset - Manual

Example:

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

Landed here in 2020 and surprised that noone has mentioned:

1.As of PHP 7.0:

$parts = $structure->parts ?? false;

2.A frowned-upon practice - the stfu operator:

$parts = @$structure->parts;