php - Check if public object property is set with variable as pointer -


ola!

so got $_post looking like:

array (     [name] => foobar     [sobject] => tbl_character     [id] => 102 ) 

and "smartobject" like:

smartobject object (     [_settings] => array         (             [table] => tbl_character             [ignores] => array                 (                     [0] => leaderid                     [1] => typeid                     [2] => senderid                     [3] => recieverid                     [4] => imageid                     [5] => fileid                     [6] => professionid                     [7] => id                 )              [prefix] => tbl_         )      [id] => 102     [worldid] =>      [accountid] => 110     [zoneid] =>      [raceid] => 1     [imageid] =>      [name] => asd      ... blabla more data ) 

what want loop through $_post , check if keys match public set property on smartobject so:

foreach($_post $key => $value) {   if(isset($object->{$key})) {     $object->{$key} = $value;    } } 

when value exists (ex. id) isset triggers , returns true, when value doesn't isset wont return true.

empty() checks if value set.

isset() should check if "variable" or "property" there, not set anything, right?

i believe code worked fine me year ago, if-statement wont trigger on name. doing wrong? has fundamentals of php changed?

how (if using php >= 5.1):

foreach($_post $key => $value) {     if (property_exists($object, $key)) {         $object->$key = $value;     } } 

here's documentation: http://www.php.net/manual/en/function.property-exists.php

from official documentation:

note: opposed isset(), property_exists() returns true if property has value null.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -