Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso's Blog:
How to use eval() without using eval() in PHP
Mar 13, 2012 @ 10:09:52

In this new post Gonzalo Ayuso talks about "using eval without using eval" in PHP applications - executing PHP code without having to use the eval function to do it.

Yes I know. Eval() is evil. If our answer is to use eval() function, we are probably asking the wrong question. When we see an eval() function all our coding smell’s red lights start flashing inside our mind. Definitely it’s a bad practice. But last week I was thinking about it. How can I eval raw PHP code without using the eval function, and I will show you my outcomes.

He includes some sample code showing a basic script with a class and a loop executing normally, then an "eval version" that puts it all in a string and executes it. He offers a different method - not an ideal one since it requires being able to write to the local file system, but prevents the need for eval - writing the PHP code to a temporary file and using a "fake eval" to pull it in.

tagged: eval execute string code temporary file include

Link:

Sameer Borate's Blog:
Refactoring 3: Replace Temp with Query
Jun 08, 2009 @ 11:18:47

Continuing on in his refactoring series (part 1 & part 2) Sameer has posted part three - a method of replacing temporary variables with calls to other methods.

Temporary variables are a integral part of any code. But a splattering of the same all over can make your code hard to understand or modify. Replace temp with query is a refactoring method where you replace temp variable expressions with methods. This method is often also required before you use the Extract Method refactoring.

In his example, he takes a variable inside a current method (base_price) and replaces it with a method call by the same name resulting in a more reusable format other methods can call rather than just computing the value themselves.

tagged: method variable temporary refactor

Link:

Mike Naberezny's Blog:
PHP Temporary Streams
Oct 20, 2008 @ 07:52:59

Following up on this post from David Sklar, Mike Naberezny has come up with a few methods of his own to come up with his "thousand string concatenations".

It's been a while since David Sklar called out to let a thousand string concatenations bloom. That discussion produced some entertaining suggestions for putting strings together such as using preg_replace and calling out to MySQL with SELECT CONCAT.

Mike goes with a bit different media of choice - the filesystem functions and streams. One example opens a file, writes to the file then rewinds back to the beginning of the stream. He modified this to make it slightly more useful (writing to memory not the file system) and shows how it could be used to make a temporary stream for testing purposes.

tagged: temporary stream concatenation zendlog filesystem

Link:

Christopher Jones' Blog:
Temporary LOBS in PHP's OCI8 Extension. Instant Client.
Jan 21, 2008 @ 12:05:00

Christopher Jones talks today on his blog about a bug he's just corrected and integrated into the release of the Oracle Instant Client that lets PHP correctly take advantage of the temporary LOBS functionality.

When PHP is done with the temporary LOB, it needs to tell Oracle to destroy it. If this isn't done, then the temporary LOB will hang around using DB space until the connection is closed. I just merged a fix worked on by Krishna Mohan and myself for bug 43497.

Example code is included showing two instances of its use - a normal use that frees the memory correctly and the other showing how to create the temporary lob to hold the data as needed.

tagged: temporary lob patch oci8 extension instant client memory leak

Link:

Tim Koschuetzki's Blog:
CakePHP 1.2 Manual
Nov 14, 2007 @ 08:42:00

As Tim Koschuetzki points out, a preliminary version of the manual for the upcoming CakePHP 1.2 release has been posted:

This version of the manual is very much a work in progress. It is being provided as a help, not an official reference, until CakePHP 1.2 reaches a final release state. While we feel this is a great start, please realize that the information provided here may be incorrect or incomplete.

There's quite a bit there already including documentation for new functionality like the config classes and URL extensions.

tagged: cakephp framework manual temporary preview cakephp framework manual temporary preview

Link:

Tim Koschuetzki's Blog:
CakePHP 1.2 Manual
Nov 14, 2007 @ 08:42:00

As Tim Koschuetzki points out, a preliminary version of the manual for the upcoming CakePHP 1.2 release has been posted:

This version of the manual is very much a work in progress. It is being provided as a help, not an official reference, until CakePHP 1.2 reaches a final release state. While we feel this is a great start, please realize that the information provided here may be incorrect or incomplete.

There's quite a bit there already including documentation for new functionality like the config classes and URL extensions.

tagged: cakephp framework manual temporary preview cakephp framework manual temporary preview

Link:

Alex Netkachov's Blog:
6 PHP coding tips to write less code
Nov 05, 2007 @ 07:58:00

Alex Netkachov has shared six tips in a new post on his blog today for how you can write less PHP code and get more done with it. It's based around another post from Arnold Daniels talking about a temporary variable method in PHP.

This tip is useful to "lazy" developers who do not even think about variable names. They may prefer magic names like ${0} and 0 is good enough variable name, why not...

His list consists of:

  • Use || (or) and && (and) operations instead of if.
  • Use ternary operator.
  • Use for instead of while.
  • In some cases PHP requires you to create a variable. [...] To handle all these situation you can create a set of small functions which shortcuts frequently used operations.
  • Explore the language you use.
  • When it is better to write more and then read the code easily, do not be lazy.

Check out Vidyut Luther's response to Alex's comments as well as one from Richard Heyes.

tagged: lazy tips less list temporary variable arnolddaniels lazy tips less list temporary variable arnolddaniels

Link:

Alex Netkachov's Blog:
6 PHP coding tips to write less code
Nov 05, 2007 @ 07:58:00

Alex Netkachov has shared six tips in a new post on his blog today for how you can write less PHP code and get more done with it. It's based around another post from Arnold Daniels talking about a temporary variable method in PHP.

This tip is useful to "lazy" developers who do not even think about variable names. They may prefer magic names like ${0} and 0 is good enough variable name, why not...

His list consists of:

  • Use || (or) and && (and) operations instead of if.
  • Use ternary operator.
  • Use for instead of while.
  • In some cases PHP requires you to create a variable. [...] To handle all these situation you can create a set of small functions which shortcuts frequently used operations.
  • Explore the language you use.
  • When it is better to write more and then read the code easily, do not be lazy.

Check out Vidyut Luther's response to Alex's comments as well as one from Richard Heyes.

tagged: lazy tips less list temporary variable arnolddaniels lazy tips less list temporary variable arnolddaniels

Link:

Arnold Daniels' Blog:
Perl like temporary variables in PHP
Nov 02, 2007 @ 09:38:00

Arnold Daniels points out a quick method for creating what he calls "perl-like temporary variables" in the global scope of a script:

When writing code in the global scope, I often have a problem where I'm overwriting a variable. This happens even more often when I work on code of somebody else. Usually has the variable which does the overwriting is usually just a temporary variable.

His code is a simple few lines that shows how it could be used when trying to write information out to a file handle. Some of the comments on the post criticize his use of the global scope but Arnold comes back with his reasoning - mostly that there is already code in the global scope and that adding something else is only adding to it, not making things worse.

tagged: temporary variable perl global scope temporary variable perl global scope

Link:

Arnold Daniels' Blog:
Perl like temporary variables in PHP
Nov 02, 2007 @ 09:38:00

Arnold Daniels points out a quick method for creating what he calls "perl-like temporary variables" in the global scope of a script:

When writing code in the global scope, I often have a problem where I'm overwriting a variable. This happens even more often when I work on code of somebody else. Usually has the variable which does the overwriting is usually just a temporary variable.

His code is a simple few lines that shows how it could be used when trying to write information out to a file handle. Some of the comments on the post criticize his use of the global scope but Arnold comes back with his reasoning - mostly that there is already code in the global scope and that adding something else is only adding to it, not making things worse.

tagged: temporary variable perl global scope temporary variable perl global scope

Link: