Let go to an example
1 $staff_items = array(“a”,”b”); 2 $address = Staff::find(1); //$address is an object storing staff data 3 foreach($staff_items as $o_row){ 4 $staff->$o_row = $_POST($o_row); //This line causes error 5 }
In the case provided above, line 5 would cause error because object $staff haven’t defined. The $staff object should be defined before use it:
1 $staff_items = array(“a”,”b”); 2 $staff = Staff::find(1); //$staff is an object storing staff data 3 foreach($staff_items as $o_row){ 4 $staff->$o_row = $_POST($o_row); 5 }
If you can't sure if your object is defined and do not want "Creating default object from empty value" appear, you can use "isset" condition to check if it exists
if (!isset($object)){}Related example :
Reference:
1 $staff_items = array(“a”,”b”); 2 $staff = Staff::find(1); 3 foreach($staff_items as $o_row){ 4 if(isset($staff)){ 5 $staff->$o_row = $_POST($o_row); 6 } 7 }
http://stackoverflow.com/questions/14806959/how-to-fix-creating-default-object-from-empty-value-warning-in-php
http://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php
No comments :
Post a Comment