Changeset 1023
- Timestamp:
- 11/10/07 13:28:34 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/lang/serialize/stubSerializableObject.php
r777 r1023 50 50 $nonAllowedProperties = $this->__doSleep(); 51 51 $propertiesToSerialize = array(); 52 foreach ( get_object_vars($this) as $name => $value) {52 foreach ($this->_extractProperties($this) as $name => $value) { 53 53 if (in_array($name, $nonAllowedProperties) == true) { 54 54 continue; trunk/src/main/php/net/stubbles/lang/stubBaseObject.php
r777 r1023 112 112 public function __toString() 113 113 { 114 return self::getStringRepresentationOf($this, get_object_vars($this)); 114 return self::getStringRepresentationOf($this, $this->_extractProperties($this)); 115 } 116 117 /** 118 * helper method to extract all properties regardless of their visibility 119 * 120 * This is a workaround for the problem that as of PHP 5.2.4 get_object_vars() 121 * is not any more capable of retrieving private properties from child classes. 122 * See http://stubbles.org/archives/32-Subtle-BC-break-in-PHP-5.2.4.html. 123 * 124 * @return array<string,mixed> 125 */ 126 protected function _extractProperties($object) 127 { 128 $properties = (array) $object; 129 $fixedProperties = array(); 130 foreach ($properties as $propertyName => $propertyValue) { 131 if (strstr($propertyName, "\0") === false) { 132 $fixedProperties[$propertyName] = $propertyValue; 133 continue; 134 } 135 136 $fixedProperties[substr($propertyName, strrpos($propertyName, "\0") + 1)] = $propertyValue; 137 } 138 139 return $fixedProperties; 115 140 } 116 141 … … 142 167 { 143 168 if (null === $properties) { 144 $properties = get_object_vars($object);169 $properties = $this->_extractProperties($object); 145 170 } 146 171 … … 151 176 } 152 177 153 $string .= ' ' . $name . '(' . self:: determineType($value) . '): ';178 $string .= ' ' . $name . '(' . self::_determineType($value) . '): '; 154 179 if (($value instanceof self) == false) { 155 180 $string .= $value . "\n"; … … 184 209 * @return string 185 210 */ 186 private static function determineType(&$value)211 private static function _determineType(&$value) 187 212 { 188 213 if (is_object($value) == false) {
