note 43192 deleted from language.operators by nlopess

From: Date: Mon, 14 Jun 2004 11:54:32 +0000
Subject: note 43192 deleted from language.operators by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71037@lists.php.net to get a copy of this message
Note Submitter: james@gogo.co.nz ---- Beware the concatenation of doom! The precedence of concatenation (.) with respect to addition and subtraction is unintuitive (and wrong in the documentation above)... <?php echo 'Foo ' . 5 - 5; ?> gives -5 because PHP does the concatentation first then subtracts 5 from the string it just created, which as an int evaluates to 0. Most times you'll notice that something is fishy if you do this accidentally, but in the case of something like <?php header('Age: ' . time() - $modified); ?> some web server installations will pass through the bogus header that results (because it ends up being header(0 - $modified)), while others will generate a 500 (internal server error) on it with no further information as to why they errored! --- James Sleeman http://www.gogo.co.nz/

« previous php.notes (#71037) next »