note 93196 added to function.echo

From: Date: Thu, 27 Aug 2009 22:01:23 +0000
Subject: note 93196 added to function.echo
Groups: php.notes 
Request: Send a blank email to php-notes+get-159953@lists.php.net to get a copy of this message
This results in a VERY strange error. <?php class String { public static function Format() { $argc = func_num_args(); $argv = func_get_args(); for ($arg_n = 0; $arg_n < $argc; $arg_n++) { $argv[0] = str_replace("\{$arg_n\}", $argv[$arg_n + 1], $argv[0]); } return $argv[0]; } } echo String::Format("My name is {0} and I am {1} years old", "Thomas", 18); ?> If I'm not mistaken, I have PHP 5.2 installed, which means the bug is probably still there, IF it is a bug. If you remove the \ (backslashes) that is right before {$arg_n} (which was my original code; I had forgotten that PHP uses them to isolate the variable in the string) the codes works fine (except the braces are now around the values, but no bugs are present). If the bug is fixed and you therefore don't see it, the bugs results in this: My name is {0} and I am {1} years old This works, however: $argv[0] = str_replace('{' . $arg_n . '}', $argv[$arg_n + 1], $argv[0]); It is of course no big disaster as I have this workaround fixing it, but is is a bit curious. I have of course considered the possibility that this is all my fault, and you simply cannot disable the function of the braces with a backslash, but you can disable the $ so one would not without reason assume that \{ would disable {. ---- Server IP: 195.184.96.15 Probable Submitter: 212.242.113.145 ---- Manual Page -- http://www.php.net/manual/en/function.echo.php Edit -- https://master.php.net/note/edit/93196 Del: integrated -- https://master.php.net/note/delete/93196/integrated Del: useless -- https://master.php.net/note/delete/93196/useless Del: bad code -- https://master.php.net/note/delete/93196/bad+code Del: spam -- https://master.php.net/note/delete/93196/spam Del: non-english -- https://master.php.net/note/delete/93196/non-english Del: in docs -- https://master.php.net/note/delete/93196/in+docs Del: other reasons-- https://master.php.net/note/delete/93196 Reject -- https://master.php.net/note/reject/93196 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159953) next »