note 100248 modified in function.get-class-vars by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Oct 2010 15:03:20 +0000 |
| Subject: | note 100248 modified in function.get-class-vars by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172938@lists.php.net to get a copy of this message | ||
All 3 of get_object_vars, get_class_vars and reflection getDefaultProperties will reveal the name of
the array. For serialization I recommend:
<?php
$cName = get_class($this);
$varTemplate= get_class_vars($cName)
foreach ($varTemplate as $name => $defaultVal) {
$vars[$name] = $this->$name; // gets actual val.
}
?>
No scan the $vars and create serialization string how you wish.
This protects against erroneous prior deserializing in maintaining the integrity of the class
template and ignoring unintended object properties.
--was--
Correction:
I wish to omit the last post, all 3 of get_object_vars, get_class_vars and reflection
getDefaultProperties will reveal the name of the array. For serialization I recommend:
$cName = get_class($this);
$varTemplate= get_class_vars($cName)
foreach ($varTemplate as $name => $defaultVal) {
$vars[$name] = $this->$name; // gets actual val.
}
No scan the $vars and create serialization string how you wish.
This protects against erroneous prior deserializing in maintaining the integrity of the class
template and ignoring unintended object properties.
http://php.net/manual/en/function.get-class-vars.php