Show
Ignore:
Timestamp:
11/10/07 13:28:34 (1 year ago)
Author:
mikey
Message:

fixed problem with PHP >= 5.2.4: get_object_vars() is not any more capable of retrieving private properties from child classes, see http://stubbles.org/archives/32-Subtle-BC-break-in-PHP-5.2.4.html

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/lang/stubBaseObject.php

    r777 r1023  
    112112    public function __toString() 
    113113    { 
    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; 
    115140    } 
    116141 
     
    142167    { 
    143168        if (null === $properties) { 
    144             $properties = get_object_vars($object); 
     169            $properties = $this->_extractProperties($object); 
    145170        } 
    146171 
     
    151176            } 
    152177 
    153             $string .= '    ' . $name . '(' . self::determineType($value) . '): '; 
     178            $string .= '    ' . $name . '(' . self::_determineType($value) . '): '; 
    154179            if (($value instanceof self) == false) { 
    155180                $string .= $value . "\n"; 
     
    184209     * @return  string 
    185210     */ 
    186     private static function determineType(&$value) 
     211    private static function _determineType(&$value) 
    187212    { 
    188213         if (is_object($value) == false) {