Ignore:
Timestamp:
2012/02/13 15:49:08 (12 years ago)
Author:
Seasoft
Message:

#1637 (クラスのオートローディング)

  • PHP 5.3.7 の is_a 関数 (PEAR 内部で使用) でエラーが発生することが判明。PHP のバグ ( https://bugs.php.net/bug.php?id=55475) に由来するものだが、PEAR を FIX 済みのリビジョンに置き換えて回避。
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/module/PEAR.php

    r20116 r21494  
    77 * PHP versions 4 and 5 
    88 * 
    9  * LICENSE: This source file is subject to version 3.0 of the PHP license 
    10  * that is available through the world-wide-web at the following URI: 
    11  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of 
    12  * the PHP License and are unable to obtain it through the web, please 
    13  * send a note to license@php.net so we can mail you a copy immediately. 
    14  * 
    159 * @category   pear 
    1610 * @package    PEAR 
     
    1913 * @author     Tomas V.V.Cox <cox@idecnet.com> 
    2014 * @author     Greg Beaver <cellog@php.net> 
    21  * @copyright  1997-2006 The PHP Group 
    22  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    23  * @version    CVS: $Id$ 
     15 * @copyright  1997-2010 The Authors 
     16 * @license    http://opensource.org/licenses/bsd-license.php New BSD License 
     17 * @version    CVS: commit 01071ee7b71e4d38c4e96fdf0ae5e411841eaec7 
    2418 * @link       http://pear.php.net/package/PEAR 
    2519 * @since      File available since Release 0.1 
     
    5145    define('OS_UNIX',    true); 
    5246    define('PEAR_OS',    'Unix'); // blatant assumption 
    53 } 
    54  
    55 // instant backwards compatibility 
    56 if (!defined('PATH_SEPARATOR')) { 
    57     if (OS_WINDOWS) { 
    58         define('PATH_SEPARATOR', ';'); 
    59     } else { 
    60         define('PATH_SEPARATOR', ':'); 
    61     } 
    6247} 
    6348 
     
    9378 * @author     Greg Beaver <cellog@php.net> 
    9479 * @copyright  1997-2006 The PHP Group 
    95  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    96  * @version    Release: 1.4.6 
     80 * @license    http://opensource.org/licenses/bsd-license.php New BSD License 
     81 * @version    Release: @package_version@ 
    9782 * @link       http://pear.php.net/package/PEAR 
    9883 * @see        PEAR_Error 
     
    10287class PEAR 
    10388{ 
    104     // {{{ properties 
    105  
    10689    /** 
    10790     * Whether to enable internal debug messages. 
     
    153136     */ 
    154137    var $_expected_errors = array(); 
    155  
    156     // }}} 
    157  
    158     // {{{ constructor 
    159138 
    160139    /** 
     
    174153            print "PEAR constructor called, class=$classname\n"; 
    175154        } 
     155 
    176156        if ($error_class !== null) { 
    177157            $this->_error_class = $error_class; 
    178158        } 
     159 
    179160        while ($classname && strcasecmp($classname, "pear")) { 
    180161            $destructor = "_$classname"; 
     
    193174    } 
    194175 
    195     // }}} 
    196     // {{{ destructor 
    197  
    198176    /** 
    199177     * Destructor (the emulated type of...).  Does nothing right now, 
     
    212190        } 
    213191    } 
    214  
    215     // }}} 
    216     // {{{ getStaticProperty() 
    217192 
    218193    /** 
     
    231206    { 
    232207        static $properties; 
     208        if (!isset($properties[$class])) { 
     209            $properties[$class] = array(); 
     210        } 
     211 
     212        if (!array_key_exists($var, $properties[$class])) { 
     213            $properties[$class][$var] = null; 
     214        } 
     215 
    233216        return $properties[$class][$var]; 
    234217    } 
    235  
    236     // }}} 
    237     // {{{ registerShutdownFunc() 
    238218 
    239219    /** 
     
    248228    function registerShutdownFunc($func, $args = array()) 
    249229    { 
     230        // if we are called statically, there is a potential 
     231        // that no shutdown func is registered.  Bug #6445 
     232        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { 
     233            register_shutdown_function("_PEAR_call_destructors"); 
     234            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; 
     235        } 
    250236        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); 
    251237    } 
    252  
    253     // }}} 
    254     // {{{ isError() 
    255238 
    256239    /** 
     
    267250    function isError($data, $code = null) 
    268251    { 
    269         if (is_a($data, 'PEAR_Error')) { 
    270             if (is_null($code)) { 
    271                 return true; 
    272             } elseif (is_string($code)) { 
    273                 return $data->getMessage() == $code; 
    274             } else { 
    275                 return $data->getCode() == $code; 
    276             } 
    277         } 
    278         return false; 
    279     } 
    280  
    281     // }}} 
    282     // {{{ setErrorHandling() 
     252        if (!is_object($data)) { 
     253             return false; 
     254        } 
     255        if (!is_a($data, 'PEAR_Error')) { 
     256            return false; 
     257        } 
     258 
     259        if (is_null($code)) { 
     260            return true; 
     261        } elseif (is_string($code)) { 
     262            return $data->getMessage() == $code; 
     263        } 
     264 
     265        return $data->getCode() == $code; 
     266    } 
    283267 
    284268    /** 
     
    320304     * @since PHP 4.0.5 
    321305     */ 
    322  
    323306    function setErrorHandling($mode = null, $options = null) 
    324307    { 
     
    358341    } 
    359342 
    360     // }}} 
    361     // {{{ expectError() 
    362  
    363343    /** 
    364344     * This method is used to tell which errors you expect to get. 
     
    383363            array_push($this->_expected_errors, array($code)); 
    384364        } 
    385         return sizeof($this->_expected_errors); 
    386     } 
    387  
    388     // }}} 
    389     // {{{ popExpect() 
     365        return count($this->_expected_errors); 
     366    } 
    390367 
    391368    /** 
     
    399376        return array_pop($this->_expected_errors); 
    400377    } 
    401  
    402     // }}} 
    403     // {{{ _checkDelExpect() 
    404378 
    405379    /** 
     
    414388    { 
    415389        $deleted = false; 
    416  
    417         foreach ($this->_expected_errors AS $key => $error_array) { 
     390        foreach ($this->_expected_errors as $key => $error_array) { 
    418391            if (in_array($error_code, $error_array)) { 
    419392                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); 
     
    426399            } 
    427400        } 
     401 
    428402        return $deleted; 
    429403    } 
    430  
    431     // }}} 
    432     // {{{ delExpect() 
    433404 
    434405    /** 
     
    444415    { 
    445416        $deleted = false; 
    446  
    447417        if ((is_array($error_code) && (0 != count($error_code)))) { 
    448             // $error_code is a non-empty array here; 
    449             // we walk through it trying to unset all 
    450             // values 
    451             foreach($error_code as $key => $error) { 
    452                 if ($this->_checkDelExpect($error)) { 
    453                     $deleted =  true; 
    454                 } else { 
    455                     $deleted = false; 
    456                 } 
    457             } 
     418            // $error_code is a non-empty array here; we walk through it trying 
     419            // to unset all values 
     420            foreach ($error_code as $key => $error) { 
     421                $deleted =  $this->_checkDelExpect($error) ? true : false; 
     422            } 
     423 
    458424            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 
    459425        } elseif (!empty($error_code)) { 
     
    461427            if ($this->_checkDelExpect($error_code)) { 
    462428                return true; 
    463             } else { 
    464                 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 
    465             } 
    466         } else { 
    467             // $error_code is empty 
    468             return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME 
    469         } 
    470     } 
    471  
    472     // }}} 
    473     // {{{ raiseError() 
     429            } 
     430 
     431            return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 
     432        } 
     433 
     434        // $error_code is empty 
     435        return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME 
     436    } 
    474437 
    475438    /** 
     
    525488            $message->error_message_prefix = ''; 
    526489            $message     = $message->getMessage(); 
    527         } 
    528  
    529         if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) { 
     490 
     491            // Make sure right data gets passed. 
     492            $r = new ReflectionClass($error_class); 
     493            $c = $r->getConstructor(); 
     494            $p = array_shift($c->getParameters()); 
     495            $skipmsg = ($p->getName() != 'message'); 
     496        } 
     497 
     498        if ( 
     499            isset($this) && 
     500            isset($this->_expected_errors) && 
     501            count($this->_expected_errors) > 0 && 
     502            count($exp = end($this->_expected_errors)) 
     503        ) { 
    530504            if ($exp[0] == "*" || 
    531505                (is_int(reset($exp)) && in_array($code, $exp)) || 
    532                 (is_string(reset($exp)) && in_array($message, $exp))) { 
     506                (is_string(reset($exp)) && in_array($message, $exp)) 
     507            ) { 
    533508                $mode = PEAR_ERROR_RETURN; 
    534509            } 
    535510        } 
     511 
    536512        // No mode given, try global ones 
    537513        if ($mode === null) { 
     
    554530            $ec = 'PEAR_Error'; 
    555531        } 
     532 
     533        if (intval(PHP_VERSION) < 5) { 
     534            // little non-eval hack to fix bug #12147 
     535            include 'PEAR/FixPHP5PEARWarnings.php'; 
     536            return $a; 
     537        } 
     538 
    556539        if ($skipmsg) { 
    557             $a = &new $ec($code, $mode, $options, $userinfo); 
    558             return $a; 
    559         } else { 
    560             $a = &new $ec($message, $code, $mode, $options, $userinfo); 
    561             return $a; 
    562         } 
    563     } 
    564  
    565     // }}} 
    566     // {{{ throwError() 
     540            $a = new $ec($code, $mode, $options, $userinfo); 
     541        } else { 
     542            $a = new $ec($message, $code, $mode, $options, $userinfo); 
     543        } 
     544 
     545        return $a; 
     546    } 
    567547 
    568548    /** 
     
    570550     * message, code and userinfo are enough. 
    571551     * 
    572      * @param string $message 
    573      * 
    574      */ 
    575     function &throwError($message = null, 
    576                          $code = null, 
    577                          $userinfo = null) 
     552     * @param mixed $message a text error message or a PEAR error object 
     553     * 
     554     * @param int $code      a numeric error code (it is up to your class 
     555     *                  to define these if you want to use codes) 
     556     * 
     557     * @param string $userinfo If you need to pass along for example debug 
     558     *                  information, this parameter is meant for that. 
     559     * 
     560     * @access public 
     561     * @return object   a PEAR error object 
     562     * @see PEAR::raiseError 
     563     */ 
     564    function &throwError($message = null, $code = null, $userinfo = null) 
    578565    { 
    579566        if (isset($this) && is_a($this, 'PEAR')) { 
    580567            $a = &$this->raiseError($message, $code, null, null, $userinfo); 
    581568            return $a; 
    582         } else { 
    583             $a = &PEAR::raiseError($message, $code, null, null, $userinfo); 
    584             return $a; 
    585         } 
    586     } 
    587  
    588     // }}} 
     569        } 
     570 
     571        $a = &PEAR::raiseError($message, $code, null, null, $userinfo); 
     572        return $a; 
     573    } 
     574 
    589575    function staticPushErrorHandling($mode, $options = null) 
    590576    { 
    591         $stack = &$GLOBALS['_PEAR_error_handler_stack']; 
     577        $stack       = &$GLOBALS['_PEAR_error_handler_stack']; 
    592578        $def_mode    = &$GLOBALS['_PEAR_default_error_mode']; 
    593579        $def_options = &$GLOBALS['_PEAR_default_error_options']; 
     
    658644    } 
    659645 
    660     // {{{ pushErrorHandling() 
    661  
    662646    /** 
    663647     * Push a new error handler on top of the error handler options stack. With this 
     
    692676        return true; 
    693677    } 
    694  
    695     // }}} 
    696     // {{{ popErrorHandling() 
    697678 
    698679    /** 
     
    717698    } 
    718699 
    719     // }}} 
    720     // {{{ loadExtension() 
    721  
    722700    /** 
    723701    * OS independant PHP extension load. Remember to take care 
     
    729707    function loadExtension($ext) 
    730708    { 
    731         if (!extension_loaded($ext)) { 
    732             // if either returns true dl() will produce a FATAL error, stop that 
    733             if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { 
    734                 return false; 
    735             } 
    736             if (OS_WINDOWS) { 
    737                 $suffix = '.dll'; 
    738             } elseif (PHP_OS == 'HP-UX') { 
    739                 $suffix = '.sl'; 
    740             } elseif (PHP_OS == 'AIX') { 
    741                 $suffix = '.a'; 
    742             } elseif (PHP_OS == 'OSX') { 
    743                 $suffix = '.bundle'; 
    744             } else { 
    745                 $suffix = '.so'; 
    746             } 
    747             return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); 
    748         } 
    749         return true; 
    750     } 
    751  
    752     // }}} 
     709        if (extension_loaded($ext)) { 
     710            return true; 
     711        } 
     712 
     713        // if either returns true dl() will produce a FATAL error, stop that 
     714        if ( 
     715            function_exists('dl') === false || 
     716            ini_get('enable_dl') != 1 || 
     717            ini_get('safe_mode') == 1 
     718        ) { 
     719            return false; 
     720        } 
     721 
     722        if (OS_WINDOWS) { 
     723            $suffix = '.dll'; 
     724        } elseif (PHP_OS == 'HP-UX') { 
     725            $suffix = '.sl'; 
     726        } elseif (PHP_OS == 'AIX') { 
     727            $suffix = '.a'; 
     728        } elseif (PHP_OS == 'OSX') { 
     729            $suffix = '.bundle'; 
     730        } else { 
     731            $suffix = '.so'; 
     732        } 
     733 
     734        return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); 
     735    } 
    753736} 
    754737 
    755 // {{{ _PEAR_call_destructors() 
     738if (PEAR_ZE2) { 
     739    include_once 'PEAR5.php'; 
     740} 
    756741 
    757742function _PEAR_call_destructors() 
     
    762747    { 
    763748        reset($_PEAR_destructor_object_list); 
    764         if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) { 
     749        if (PEAR_ZE2) { 
     750            $destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo'); 
     751        } else { 
     752            $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo'); 
     753        } 
     754 
     755        if ($destructLifoExists) { 
    765756            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); 
    766757        } 
     758 
    767759        while (list($k, $objref) = each($_PEAR_destructor_object_list)) { 
    768760            $classname = get_class($objref); 
     
    783775 
    784776    // Now call the shutdown functions 
    785     if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) { 
     777    if ( 
     778        isset($GLOBALS['_PEAR_shutdown_funcs']) && 
     779        is_array($GLOBALS['_PEAR_shutdown_funcs']) && 
     780        !empty($GLOBALS['_PEAR_shutdown_funcs']) 
     781    ) { 
    786782        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { 
    787783            call_user_func_array($value[0], $value[1]); 
     
    790786} 
    791787 
    792 // }}} 
    793788/** 
    794789 * Standard PEAR error class for PHP 4 
     
    802797 * @author     Gregory Beaver <cellog@php.net> 
    803798 * @copyright  1997-2006 The PHP Group 
    804  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    805  * @version    Release: 1.4.6 
     799 * @license    http://opensource.org/licenses/bsd-license.php New BSD License 
     800 * @version    Release: @package_version@ 
    806801 * @link       http://pear.php.net/manual/en/core.pear.pear-error.php 
    807802 * @see        PEAR::raiseError(), PEAR::throwError() 
     
    810805class PEAR_Error 
    811806{ 
    812     // {{{ properties 
    813  
    814807    var $error_message_prefix = ''; 
    815808    var $mode                 = PEAR_ERROR_RETURN; 
     
    820813    var $backtrace            = null; 
    821814 
    822     // }}} 
    823     // {{{ constructor 
    824  
    825815    /** 
    826816     * PEAR_Error constructor 
     
    853843        $this->mode      = $mode; 
    854844        $this->userinfo  = $userinfo; 
    855         if (function_exists("debug_backtrace")) { 
    856             if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) { 
    857                 $this->backtrace = debug_backtrace(); 
    858             } 
    859         } 
     845 
     846        if (PEAR_ZE2) { 
     847            $skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace'); 
     848        } else { 
     849            $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace'); 
     850        } 
     851 
     852        if (!$skiptrace) { 
     853            $this->backtrace = debug_backtrace(); 
     854            if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { 
     855                unset($this->backtrace[0]['object']); 
     856            } 
     857        } 
     858 
    860859        if ($mode & PEAR_ERROR_CALLBACK) { 
    861860            $this->level = E_USER_NOTICE; 
     
    865864                $options = E_USER_NOTICE; 
    866865            } 
     866 
    867867            $this->level = $options; 
    868868            $this->callback = null; 
    869869        } 
     870 
    870871        if ($this->mode & PEAR_ERROR_PRINT) { 
    871872            if (is_null($options) || is_int($options)) { 
     
    874875                $format = $options; 
    875876            } 
     877 
    876878            printf($format, $this->getMessage()); 
    877879        } 
     880 
    878881        if ($this->mode & PEAR_ERROR_TRIGGER) { 
    879882            trigger_error($this->getMessage(), $this->level); 
    880883        } 
     884 
    881885        if ($this->mode & PEAR_ERROR_DIE) { 
    882886            $msg = $this->getMessage(); 
     
    891895            die(sprintf($format, $msg)); 
    892896        } 
    893         if ($this->mode & PEAR_ERROR_CALLBACK) { 
    894             if (is_callable($this->callback)) { 
    895                 call_user_func($this->callback, $this); 
    896             } 
    897         } 
     897 
     898        if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) { 
     899            call_user_func($this->callback, $this); 
     900        } 
     901 
    898902        if ($this->mode & PEAR_ERROR_EXCEPTION) { 
    899903            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING); 
     
    902906    } 
    903907 
    904     // }}} 
    905     // {{{ getMode() 
    906  
    907908    /** 
    908909     * Get the error mode from an error object. 
     
    911912     * @access public 
    912913     */ 
    913     function getMode() { 
     914    function getMode() 
     915    { 
    914916        return $this->mode; 
    915917    } 
    916918 
    917     // }}} 
    918     // {{{ getCallback() 
    919  
    920919    /** 
    921920     * Get the callback function/method from an error object. 
     
    924923     * @access public 
    925924     */ 
    926     function getCallback() { 
     925    function getCallback() 
     926    { 
    927927        return $this->callback; 
    928928    } 
    929929 
    930     // }}} 
    931     // {{{ getMessage() 
    932  
    933  
    934930    /** 
    935931     * Get the error message from an error object. 
     
    942938        return ($this->error_message_prefix . $this->message); 
    943939    } 
    944  
    945  
    946     // }}} 
    947     // {{{ getCode() 
    948940 
    949941    /** 
     
    958950     } 
    959951 
    960     // }}} 
    961     // {{{ getType() 
    962  
    963952    /** 
    964953     * Get the name of this error/exception. 
     
    972961    } 
    973962 
    974     // }}} 
    975     // {{{ getUserInfo() 
    976  
    977963    /** 
    978964     * Get additional user-supplied information. 
     
    986972    } 
    987973 
    988     // }}} 
    989     // {{{ getDebugInfo() 
    990  
    991974    /** 
    992975     * Get additional debug information supplied by the application. 
     
    999982        return $this->getUserInfo(); 
    1000983    } 
    1001  
    1002     // }}} 
    1003     // {{{ getBacktrace() 
    1004984 
    1005985    /** 
     
    10221002    } 
    10231003 
    1024     // }}} 
    1025     // {{{ addUserInfo() 
    1026  
    10271004    function addUserInfo($info) 
    10281005    { 
     
    10341011    } 
    10351012 
    1036     // }}} 
    1037     // {{{ toString() 
     1013    function __toString() 
     1014    { 
     1015        return $this->getMessage(); 
     1016    } 
    10381017 
    10391018    /** 
     
    10431022     * @access public 
    10441023     */ 
    1045     function toString() { 
     1024    function toString() 
     1025    { 
    10461026        $modes = array(); 
    10471027        $levels = array(E_USER_NOTICE  => 'notice', 
     
    10821062                       $this->userinfo); 
    10831063    } 
    1084  
    1085     // }}} 
    10861064} 
    10871065 
     
    10931071 * End: 
    10941072 */ 
    1095 ?> 
Note: See TracChangeset for help on using the changeset viewer.