note 127200 added to function.isset

From: Date: Mon, 27 Jun 2022 15:14:18 +0000
Subject: note 127200 added to function.isset
Groups: php.notes 
Request: Send a blank email to php-notes+get-218624@lists.php.net to get a copy of this message
I kept having problems with a nested object always returning false when using isset() to check various levels. I assume this was due to some of the levels having values but not being variables. At any given time the subobjects might or might not have been set with values, but I needed to check if they did before doing further processing. Sample nested object: $sale->vehicle->model->year Doing a var_dump() at any of these levels (i.e. var_dump($sale->vehicle->model) would display a value, if the object was populated. isset($sale->vehicle->model) would always return a false on subobjects. My solution is: if (($sale->vehicle->model->year) ? (true) ? (false)) { //do some processing here because we found it } This seems to get around the isset() restriction that requires the operand to be a variable. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.133 (proxied: 2600:1700:9780:6290:a15d:4c01:1ceb:7933) ---- Manual Page -- https://php.net/manual/en/function.isset.php Edit -- https://main.php.net/note/edit/127200 Del: integrated -- https://main.php.net/note/delete/127200/integrated Del: useless -- https://main.php.net/note/delete/127200/useless Del: bad code -- https://main.php.net/note/delete/127200/bad+code Del: spam -- https://main.php.net/note/delete/127200/spam Del: non-english -- https://main.php.net/note/delete/127200/non-english Del: in docs -- https://main.php.net/note/delete/127200/in+docs Del: other reasons-- https://main.php.net/note/delete/127200 Reject -- https://main.php.net/note/reject/127200 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218624) next »