News Feed
Sections




News Archive
feed this:

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
March 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.

0 comments voice your opinion now!
eval execute string code temporary file include


Sameer Borate's Blog:
Refactoring 3 Replace Temp with Query
June 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.

0 comments voice your opinion now!
method variable temporary refactor


Mike Naberezny's Blog:
PHP Temporary Streams
October 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.

0 comments voice your opinion now!
temporary stream concatenation zendlog filesystem


Christopher Jones' Blog:
Temporary LOBS in PHP's OCI8 Extension. Instant Client.
January 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.

0 comments voice your opinion now!
temporary lob patch oci8 extension instant client memory leak


Tim Koschuetzki's Blog:
CakePHP 1.2 Manual
November 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.

0 comments voice your opinion now!
cakephp framework manual temporary preview cakephp framework manual temporary preview


Alex Netkachov's Blog:
6 PHP coding tips to write less code
November 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.

0 comments voice your opinion now!
lazy tips less list temporary variable arnolddaniels lazy tips less list temporary variable arnolddaniels


Arnold Daniels' Blog:
Perl like temporary variables in PHP
November 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.

0 comments voice your opinion now!
temporary variable perl global scope temporary variable perl global scope


Webdigity.com:
Caching your pages with PHP
July 16, 2007 @ 18:55:00

On the Webdigity.com forums, there's this new tutorial posted showing how to create a simple caching system with PHP for your site (using cached files).

A problem that this process creates is the server overhead. Every time we execute a query in the database, the instance of our script will call the DBMS, and then the DBMS will send the results of the query. This is time consuming, and especially for sites with heavy traffic is a real big problem.

There are two ways to solve this if you want to make your site faster. First is optimizing the queries Visit through proxy, but we will not talk about this at the present article. The second and most valuable is using some kind of custom caching technique.

Their code, contained in an easy-to-use class, makes it simple to cache the contents of a page just by setting the stop to start the caching from (and where to end).

1 comment voice your opinion now!
caching page class file custom temporary caching page class file custom temporary


Tim Koschuetzki's Blog:
Composing Methods Remove Assignments to Parameters
July 06, 2007 @ 10:21:00

In another part of his "Composing Methods" series, Tim Koschuetzki posts about removing assignments to parameters today - working with a temporary variable inside a method rather than the actual passed in value.

When your code assigns to a parameter in a function/method, use a temporary variable instead. [...] It will make your code much more readable and prevents by-reference confusion and therefore big problems in the future.

His example code uses the illustration of calling a price() method in a class to modify the inputVal value based on other inputted information. His suggestion is to not work with the actual inputVal value passed in (so as to avoid issues if it happens to be passed my reference later), but to work with a temporary variable - $result - inside the method.

1 comment voice your opinion now!
method compose remove assignment parameter temporary variable method compose remove assignment parameter temporary variable


PHP-Coding-Practices.com:
Composing Methods Split Temporary Variable
July 04, 2007 @ 11:26:00

On the PHP-Coding-Practices.com blog, there's a tutorial posted from Tim Koschuetzki in his "Composing Methods" series looking at assigning temporary variables.

When you have the same temporary variable assigned to more than once, split it up into two, unless it is a loop variable. [...] Temporary variables have various uses. They can be used as counters in loops, as collecting variables building up a result or as simple containers containing the result of a long-winded expression for easy reference.

He offers suggestions of using temporary variables, including changing references of it after use and making a new temp variable following the second assignment of the first one. Some sample code is included to illustrate the points made.

0 comments voice your opinion now!
temporary variable compose method tutorial temporary variable compose method tutorial



Community Events





Don't see your event here?
Let us know!


configure symfony code api framework unittest library language community threedevsandamaybe wordpress release interview series podcast application introduction developer list install

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework