note 43192 added to language.operators

From: Date: Sat, 12 Jun 2004 23:21:47 +0000
Subject: note 43192 added to language.operators
Groups: php.notes 
Request: Send a blank email to php-notes+get-71009@lists.php.net to get a copy of this message
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/ ---- Manual Page -- http://www.php.net/manual/en/language.operators.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43192 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43192&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43192&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71009) next »