News for hackers. Stuff that matters.
Re:Let's make the web faster: PHP performance tips by Google by michaelchisari on Friday June 03, 2011 @01:09AM (#2615219)
This example:

  $description = strip_tags($_POST['description']);
  echo $description;

  ...

  echo strip_tags($_POST['description']);
Sacrifices readability for performance. Sometimes that's a worthwhile compromise, but often times not. And if you plan on referencing $description more than once (which, most code would), then it wouldn't make much sense to run strip_tags each time.
Re:Let's make the web faster: PHP performance tips by Google by wvenable on Friday June 03, 2011 @02:14AM (#2615357)
I doubt it even sacrifices performance. The temporary results of strip_tags() still has to be allocated in order to be echo'd out -- so you're using the same amount of memory. $description will be de-allocated as soon as it goes out of scope.
Re:Let's make the web faster: PHP performance tips by Google by eropple on Friday June 03, 2011 @02:44AM (#2615406)
Memory cleanup isn't free (the instance of $description in scope), and unless you return by-reference, you're making a double copy.
Re:Let's make the web faster: PHP performance tips by Google by smalyshev on Friday June 03, 2011 @04:24AM (#2615571)
Both versions of the code do exactly the same: 1. Take description from memory 2. Allocate string and put the stripped version there 3. Output the string (here you might save if you don't use output buffering since no copying to the buffer happens but just output) 4. Release the memory allocated in 2.
Re:Let's make the web faster: PHP performance tips by Google by eropple on Friday June 03, 2011 @10:17AM (#2616397)
Whoops, you're right--I was thinking it was getting returned, rather than output.
Re:Let's make the web faster: PHP performance tips by Google by johnx123 on Friday June 03, 2011 @02:31AM (#2615380)
Agreed. Should be:

$stripped_description = strip_tags($_POST['description']); echo $stripped_description;