ãããµã¤ãã¦ãºã»ã¢ããã³ãã«ã¬ã³ãã¼ãã®2æ¥ç®ã§ãï¼ããã¾ã§ã®è¨äºä¸è¦§ï¼ã
ããã«ã¡ã¯ãGaroonã®ã¡ã³ããã³ã¹ãã¼ã ã®æ¨ªç°ã§ãã
JavaScriptã ãªãã ã¨è¨ã£ã¦ãã¾ãããä»æ¥ã¯PHPã®ãã¼ã¸ã§ã³ã¢ããã®è©±ã§ãã
以å話é¡ã«ãªã£ã¦ããè¨äºãã³ã¡ã³ããã¿ãã¨ãæããããã¦ã¤ãã¦ãããªãã§ãããããããã¤ãã¯PHPã®ãµãã¼ããåãã¦ãPHP5.4ã¸ã®ç§»è¡ãããªãã¦ã¯ããã¾ãããgkbrã¢ãã§ãããï¼ç¹æ®µããããã¨ã§ãªãã¨åç½®ããã¦ããã¾ãããã§ããã ãã³ã¼ãã触ããã«PHP5.4ã§åããããã«ã¯ãã©ããããããã®ããã¡ãã¡ããã¨èª¬æãã¡ããã¾ãï¼
PHP5.4対ç
ã¾ãã¯ãphp.iniãã¡ã¤ã«ã®E_STRICTãåãã¾ããPHP5.4ã§ã¯ããã©ã«ãã§ONã«ãªãã¾ãã®ã§ãæ示çã«åãã¾ãããã
Call-time pass-by-reference(é¢æ°å¼ã³åºãæã®åç §æ¸¡ã)ãPHPã®æ©è½ã¨ãã¦åé¤ããã¦ãã¾ã£ã¦ããã®ã§ããªãã·ã§ã³ãåé¤ãã¦ãã ãããã¡ãªã¿ã«é¢æ°å¼ã³åºãæã®åç §æ¸¡ãã¨ã¯ã以ä¸ã®ãããªã³ã¼ãã§ãã
/** * @param $a $aã¯åç §æ¸¡ã * @param $b $bã¯å¤æ¸¡ã * @see http://php.net/manual/ja/language.references.pass.php * @return bool * ãã®é¢æ°ã ãã§ã¯ãFatal Errorã¯çºçããªããã¨ã«æ³¨æãã¦ãã ãã **/ function somethingMethod( &$a, $b ) { return true; } $a = 1; $b = 2; /** ããã§ã¨ã©ã¼ãçºç */ somethingMethod(&$a, $b);
php.iniã®è¨å®
error_reporting = E_ALL & ~E_STRICT ;; åé¤ãã ;;allow_call_time_pass_reference = On
ã»ãã«ãåé¤ããã¦ãããã£ã¬ã¯ãã£ããããã¾ãã®ã§ãããã§ç¢ºèªãã¦ã¿ã¦ãã ããã
call_time_referenceã«å¯¾å¿ãã
PHP5.4ã§ã¯ Call-time pass-by-referenceã php -l ã³ãã³ãã§è¦ã¤ãããã¨ãã§ããã®ã§ãå®è¡ããã¨ãåé¡ã®ã³ã¼ããè¦ã¤ãããã¨ãã§ãã¾ããç´ æ´ãããï¼ããã¨E_STRICTåãã§ãPHP5.4ã¯åãããåç¶ã§ãï¼
php -l trunk/code/something.php Fatal error: Call-time pass-by-reference has been removed in trunk/code/something.php on line 112 ...
ã¡ãªã¿ã«ç¤¾å ã®ã³ã¼ãã§ã¯150ç®æã»ã©ã§ãã(´ã»Ïã»`)ï¾ï½¨ãããã対å¿ããããã ãããã¯åãããã«ãªãã¾ããã¼ã
ãã¨ãphp -lã§Fatal Errorãçºçãã¦ãã¾ãã¨ãå¾ã®ã³ã¼ãã¯ãè¦ã¦ãããªãã®ã§ãä¿®æ£ã¨ãªã³ããç¹°ãè¿ãã¦ãã ãããã
æååoffsetåé¡
ä¸ã®ï¼ã¤ã§PHPãã®ãã®ã¯åãã¾ãããæååã®Offsetåé¡ã¯ãé常ã«è¾ãåé¡ã§ãã¦ãå質ä¿è¨¼ã¨ããç¹ã«é¢ãã¦ã¯å帰試é¨ãå¿ è¦ã§ãããã
(´ã»Ïã»`)ï½·ï¾ï½²â¦
$str = 'abc'; var_dump($str['1']); var_dump(isset($str['1'])); var_dump($str['1.0']); var_dump(isset($str['1.0'])); var_dump($str['x']); var_dump(isset($str['x'])); var_dump($str['1x']); var_dump(isset($str['1x']));
PHP5.3ã®å ´å
string(1) "b" bool(true) string(1) "b" bool(true) string(1) "a" bool(true) string(1) "b" bool(true)
PHP5.4ã®å ´å
string(1) "b" bool(true) Warning: Illegal string offset '1.0' in /tmp/t.php on line 7 string(1) "b" bool(false) Warning: Illegal string offset 'x' in /tmp/t.php on line 9 string(1) "a" bool(false) string(1) "b" bool(false)
- çå½å¤å®ãã²ã£ããè¿ã
- æ°ãã«ã¨ã©ã¼ãçºçããããã«
E_STRICTãè¦ã¤ãåºãæ¹æ³
E_STRICT対å¿ãéãã¦ãä»ã¾ã§æãã対å¿ãåºæ¥ãã°ãPHP5.4ã§ãåãã¾ãããã®æ¹æ³ã¯E_STRICTã対å¿ãããã¨ããæ¹åãã§ãã
E_STRICTã®ä¸ã«ã¯ã³ã³ãã¤ã«æã«çºçãããã®ãããã¾ãããªã®ã§ãphpã®å®è¡æã«ã¨ã©ã¼ã¬ãã«ãMAXã«ãã¦ãphp -lããããã¨ããã幸ãã«ãªãã¾ããã¨ãã£ã¦ãå®è¡æã¨ã©ã¼ãå¤ããç¶æ¿é¢ä¿ãããããã®ãããããè¦åãã¦ããã¾ããããå®éã«ã³ã¼ããåãããªãã¦ããåºããã¨ã©ã¼ãããã¾ãã
class ParentClass { public function methodA($a,$b){} //E_STRICT error } class ChildClass extends ParentClass { public function methodA($a){} }
ã¨ã©ã¼ãMAXã«ãã¦php -lãããã¾ãã
./plain-php5.4.8/bin/php -d display_errors=1 -d html_errors=0 -d error_prepend_string=" " -d error_append_string=" " -d error_reporting=4095 -l sample.php Strict Standards: Declaration of ChildClass::methodA() should be compatible with ParentClass::methodA($a, $b) in sample.php on line 17
ãã¹ãã³ã¼ãã®tips
ãã£ã±ãã©ããã¦ããã¹ããæ¸ããªãã¨ããæãããã¾ããããããæã¯ãã¬ãã¥ã¼ã¢ã¼ã¨QAã¨ã§ååãã¦ä¹ãåãä»ããã¾ããããtest_helperã使ãã¨å°ã幸ãã«ãªããããããã¾ããã
é¢æ°ã®ä¸ã«ããã»ã¹ãçµäºé¢æ°ããã£ã¦ããã¹ããéä¸çµäºãã
ã¯ã©ã¹ã»ã¡ã½ãããªãã¾ã ãäºæ ã¯ãã·ã§ãããã¹ãã³ã¼ããæ¸ããã£ã³ã¹ãããã¾ãããã¬ã¬ã·ã¼ã³ã¼ãæ¹åã¬ã¤ãã(ãã¤ã±ã«ã»Cã»ãã§ã¶ã¼ãºè) ã§ã¯ãã°ãã¼ãã«é¢æ°ã¯ããªãã¸ã§ã¯ãæ¥åé¨ã§è§£æ±ºããã¾ãããPHPã¯ãããªã«çããªãã§ãã
ãã¨ãã°ãããªã³ã¼ãããã£ã¦ã
function cybozu_throw_error($err_msg) { print_error($err_msg); die();//ææª(>_<;) }
ãããªã¨ããã«ä½¿ããã¦ããã¨ã
class ClassA { public function someMethod() { if( $this->isValid() ) { cybozu_throw_error("invalid in some Method"); } } }
ClassA::isValid()ã®è¿ãå¤ãtrueã ã¨ãPHPUnitãéä¸ã§çµäºãã¦ããã¹ããã¾ã¾ãªãã¾ããã
peclã©ã¤ãã©ãªã®test_helperãå©ç¨ãã
- https://github.com/sebastianbergmann/php-test-helpers
- http://php.net/manual/ja/function.rename-function.php
ãããªãããã§ãã°ãã¼ãã«é¢æ°ã®ç½®ãæããã§ããããã¾ãã
function fake_cybozu_throw_error() {/* do nothing */} rename_function( "cybozu_throw_error", "orig_cybozu_throw_error"); rename_function( "fake_cybozu_throw_error", "cybozu_throw_error");
Garoonãæ¹åãã¦ãã ããããã°ã©ãåé
PHPããã¥ã¢ã«ã«ã®ã£ã¦ãããã¨ãã»ã¨ãã©ã§ããè¶ãæ¿ããæããããã§ã(ã¹ã¤ãã»ã³)ãã¬ã¬ã·ã¼ã³ã¼ãã触ã£ã¦ããã¨ã ãã ãå¨ããè¦ããªããªã£ã¦ããã®ã§ããããããæ¹æ³ããããã¼ãçãªãã¼ã¸ã§ã³ã¢ãã対å¿æ¹æ³ãç´¹ä»ãã¦ã¿ã¾ãããå°ãã¥ã¤PHP5.4ã«åãã¦ãæºååºæ¥ãã¨ãããããã¯ãã§ãããããªãå ¨é¨ãããã¨ããã¨å¤§ããã©ãããã®ã§ãç¨æ³ç¨éãå®ã£ã¦ããã°ãã¾ãããã
åãç¾å¨é¢ãã£ã¦ããGaroonãæ¹åãã¦ãã ããåå¿ãåéãã¦ããã¾ããããããã¯æ¡ç¨æ å ±ã¸ã
ã»ãã¨ãããã¦ãã ããã»ã»ã» ä¸ç·ã«ããã°ãã¾ãããã¼ã
ææ¥ã¯ãWebãã©ã¦ã¶ã§ããªãã¯ä½é¨ãããéããã¾ããã楽ãã¿ã«ã