binaryã¸ã®ãã£ã¹ãã£ã¦â¦â¦ï¼
æ¨æ¥ã®「NULLへのキャストって……?」ã§ã¯ã¹ã«ã¼ãããã©ãããã¥ã¢ã«ã®å¼ç¨é¨åã«ãã£ã(binary)
ãæ°ã«ãªã£ã人ãããã¯ãã
使ç¨å¯è½ãªãã£ã¹ãã以ä¸ã«ç¤ºãã¾ãã
- (int), (integer) - æ´æ°ã¸ã®ãã£ã¹ã
- (bool), (boolean) - è«çå¤ã¸ã®ãã£ã¹ã
- (float), (double), (real) - float ã¸ã®ãã£ã¹ã
- (string) - æååã¸ã®ãã£ã¹ã
- (array) - é åã¸ã®ãã£ã¹ã
- (object) - ãªãã¸ã§ã¯ãã¸ã®ãã£ã¹ã
- (unset) - NULL ã¸ã®ãã£ã¹ã (PHP 5)
(binary) ã«ãããã£ã¹ãã b ãã¬ãã£ãã¯ã¹ã®ãµãã¼ãã¯ãPHP 5.2.1 ã§è¿½å ããã¾ããã
ãªã¹ãã«ã¯å ¥ã£ã¦ãªããã©ãæå¾ã«ããã£ã¨ä¸æ追å ããã¦ããã¤ãå ·ä½çãªèª¬æããªã«ãæ¸ããã¦ããªãã®ã§ã©ã使ããã®ãªã®ããã£ã±ãããããªãã
å ã®ããã¥ã¢ã«ã«ã¯ãã®ãããªä¾ãè¼ã£ã¦ããã
ãªãã©ã«æååãå¤æ°ãããã¤ããªæååã«ãã£ã¹ããã¾ãã<?php $binary = (binary) $string; $binary = b"binary string"; ?>
ããããPHPã®æååã¯å
ããï¼å
é¨ã¨ã³ã³ã¼ãã£ã³ã°ãªã©ãæããªãï¼ãã ã®ãã¤ãå*1ãªã®ã§ããããããã£ã¹ãããæå³ãããããªãã
試ãã«ãããªãã¨ããã¦ã¿ããããªã«ãå¤ãã£ãããã«ã¯è¦ããªãã
<?php var_dump('ããã«ã¡ã¯'); // string(15) "ããã«ã¡ã¯" var_dump(b'ããã«ã¡ã¯'); // string(15) "ããã«ã¡ã¯" var_dump((binary)'ããã«ã¡ã¯'); // string(15) "ããã«ã¡ã¯" var_dump('ããã«ã¡ã¯' === (binary)'ããã«ã¡ã¯'); // bool(true) var_dump('ããã«ã¡ã¯' === b'ããã«ã¡ã¯'); // bool(true) ?>
å®éãã¡ããã©æå ã«ãã£ãPHP 5.4.13ã®zend_language_scanner.lã§ã¯ãã®ããã«å®ç¾©ããã¦ããã
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("string"|"binary"){TABS_AND_SPACES}")" { return T_STRING_CAST; }
å®ã¯PHP6ã¸ã®å¸ç³ã ã£ãï¼
ã©ãããããï¼ãã¤ã¦ã®æ§æ³ã®ï¼PHP6ã§å
é¨å®è£
ãUnicodeã«ãªããã¨ã¸ã®å¸ç³ã ã£ãããã§ãç¾å¨ã§ã¯ç¹ã«æå³ãç¡ãã£ã½ãã
Unicodeæååãããã©ã«ãã«ãªã£ãæã«ãã¤ãåã表ç¾ããããã«ç¨æããã¦ãããã®ãããã
ãããPHP6ã§ã®Unicodeåã¯æ念ãã¦ç¾å¨ã®5.3ãã®éãæ©ãã§ãã®ã§â¦â¦ãããªãåï¼