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

Matthias Noback:
Combing legacy code string by string
Apr 18, 2018 @ 14:15:59

In a new post to his site Matthias Noback takes a look at legacy applications and two things that most of them seem to have in common: classes that are too large and too generic methods. In this post he discusses these two topics and some of the tactics you can use to help refactor and resolve them.

I find it very curious that legacy (PHP) code often has the following characteristics:
  • Classes with the name of a central domain concept have grown too large.
  • Methods in these classes have become very generic.

He starts by tackling the "classes too large" problem, suggesting that it's usually just a matter of developers slowly adding to existing functionality rather than introducing large chunks of code all at once. Moving on to the "generic methods" issue, he lays out a common scenario showing how a method evolves over time to repurpose it for other uses thank its original intent. He recommends "taking a step back" and picking apart the code to make the functionality more specific in the places it's used.

tagged: legacy application generic method large class tutorial

Link: https://matthiasnoback.nl/2018/04/combing-legacy-code-string-by-string/

Christian Weiske's Blog:
First work on the Generic PHP Application Installer
Sep 27, 2010 @ 13:57:51

In a recent post to his site Christian Weiske shares some of the first steps being made toward an installer he's made that could be used for installing PHP applications of just about any type.

Half a year after I collected requirements for a generic PHP application installer, Kore already implemented the first bits of it for the Arbit installer, which is supposed to be generic enough for other PHP applications, too. He also held a talk at the PHP Unconference in Hamburg, collecting more requirements for it. There is already some code in arbit's svn repository which at least generates a .phar file that checks your application requirements and collects configuration options.

An example of a simple build is included that will create the Arbit installer package that, when executed, will give a basic configuration screen. They suggest making .phar files executable by the web server too (interpreted by PHP) just to make things simpler.

tagged: generic application installer arbit example

Link:

Jani Hartikainen's Blog:
Reusable "generic" actions in Zend Framework
Dec 29, 2008 @ 13:55:13

In this recent blog entry Jani Hartikainen looks at the creation of generic actions for Zend Framework applications - methods that can be used to help eliminate code duplication:

Sometimes you will need nearly the same functionality in many actions. [...] There are several ways to deal with this, such as moving the code into a separate function, or an action helper. But in this post, I'm going to introduce so called "generic actions" - parametrized, easy to reuse actions - which is an idea similar to django generic views.

His example takes a generic action - one that grabs and output records from a table - and modifies it to take in parameters from the defining function as to which action/controller/model and ID to use. Then this action can be used over and over in multiple places without having to do any copy and paste coding.

tagged: generic zction zend framework reuse duplicate

Link:

CodeUtopia Blog:
Generic collections in PHP
Sep 19, 2008 @ 17:06:53

On the CodeUtopia blog Jani Hartikainen has posted some thoughts on generic collections in PHP and a class he's created to try to introduce them to the language.

Strictly typed languages usually use "generic" collection classes instead of arrays. They are kind of like PHP arrays which the programmer can tell which type of items to accept. This is of course only natural when you don't have dynamic typing, but it can also be useful for avoiding programming errors, so I thought I'd try making a basic generic collection class in PHP...

He shows how ti works with a simple code example - creating a new collection type (a string) and pushing the data into it. Calling the add() method on the string throws an exception because of the data type defined. You can grab the code from his svn repository.

tagged: generic collection class download svn example string

Link:

David Walsh's Blog:
Using PHP Generic Objects To Organize Your Code
Dec 07, 2007 @ 13:52:00

David Walsh has put together and posted a class he's created around creating generic objects to help with code organization.

I like using PHP classes to keep my code organized and easy to maintain. I know that they consume more memory than simply using an array or variable system, but if memory is an issue, I'd get more memory. Saving time by coding in a maintainable fashion is more important to me than upgrading a server. I've written a very generic, flexible PHP class that I use in my PHP code to get and set variables for use within the page.

His class is included as are two example of its use - a basic option that sets properties on the object and an example of its use with a database, parsing the results into an object with a load() call.

tagged: generic object class example organize generic object class example organize

Link:

David Walsh's Blog:
Using PHP Generic Objects To Organize Your Code
Dec 07, 2007 @ 13:52:00

David Walsh has put together and posted a class he's created around creating generic objects to help with code organization.

I like using PHP classes to keep my code organized and easy to maintain. I know that they consume more memory than simply using an array or variable system, but if memory is an issue, I'd get more memory. Saving time by coding in a maintainable fashion is more important to me than upgrading a server. I've written a very generic, flexible PHP class that I use in my PHP code to get and set variables for use within the page.

His class is included as are two example of its use - a basic option that sets properties on the object and an example of its use with a database, parsing the results into an object with a load() call.

tagged: generic object class example organize generic object class example organize

Link:

Maarten Balliauw's Blog:
Generic arrays in PHP
Oct 25, 2007 @ 13:50:00

On his blog, Maarten Balliauw has an interesting new post dealing with the use of generics in PHP:

Assuming everyone knows what generics are, let's get down to business right away. PHP does not support generics or something similar, though it could be very useful in PHP development. Luckily, using some standard OO-practises, a semi-generic array can easily be created, even in multiple ways! Here's the road to PHP generics.

He shows the two ways to make generics possible - the hard way (simple inheritance and type hinting) and the more flexible way (a GenericArrayObject that extends the normal ArrayObject to make appending and validating the contents of the array simple).

tagged: generic array arrayobject extend filter validation generic array arrayobject extend filter validation

Link:

Maarten Balliauw's Blog:
Generic arrays in PHP
Oct 25, 2007 @ 13:50:00

On his blog, Maarten Balliauw has an interesting new post dealing with the use of generics in PHP:

Assuming everyone knows what generics are, let's get down to business right away. PHP does not support generics or something similar, though it could be very useful in PHP development. Luckily, using some standard OO-practises, a semi-generic array can easily be created, even in multiple ways! Here's the road to PHP generics.

He shows the two ways to make generics possible - the hard way (simple inheritance and type hinting) and the more flexible way (a GenericArrayObject that extends the normal ArrayObject to make appending and validating the contents of the array simple).

tagged: generic array arrayobject extend filter validation generic array arrayobject extend filter validation

Link:

IBM developerWorks:
Batch processing in PHP
Dec 07, 2006 @ 15:06:00

Both this post on the Zend Developer Zone and tis post on the International PHP Magazine's website point to a new article over on the IBM developerWorks website by Jack Herrington, Batch processing with PHP.

What do you do when you have a feature in your Web application that takes longer than a second or two to finish? You need some type of offline processing solution. Check out several methods for offline servicing of long-running jobs in your PHP application.

He talks about cron and its role in offline processing (including a basic primer on its format) before getting into the example itself. He looks at three examples:

  • building an email queue
  • building a generic queue system
  • dumping out the database
Each example comes complete with code and descriptions to help you work them up on you very own system.

tagged: batch process cron mail quene generic database dump batch process cron mail quene generic database dump

Link:

IBM developerWorks:
Batch processing in PHP
Dec 07, 2006 @ 15:06:00

Both this post on the Zend Developer Zone and tis post on the International PHP Magazine's website point to a new article over on the IBM developerWorks website by Jack Herrington, Batch processing with PHP.

What do you do when you have a feature in your Web application that takes longer than a second or two to finish? You need some type of offline processing solution. Check out several methods for offline servicing of long-running jobs in your PHP application.

He talks about cron and its role in offline processing (including a basic primer on its format) before getting into the example itself. He looks at three examples:

  • building an email queue
  • building a generic queue system
  • dumping out the database
Each example comes complete with code and descriptions to help you work them up on you very own system.

tagged: batch process cron mail quene generic database dump batch process cron mail quene generic database dump

Link:


Trending Topics: