DevShed: Keeping Track of Objects when Using Destructors in PHP 5
302538
Devshed continues their series looking at the use of destructors in PHP5 applications with part three, a method for keeping track of objects you've created during execution.   In this third part of the series, I'm going to show you how to retrieve some useful information about a specific object, including its properties and methods, prior to its being destroyed by the PHP parser via the implementation of a simple destructor.   Their new user class extracts the details about each of the objects right before they're destroyed via a call to get_object_vars and a loop to display the property and its value.
360849
On the Zend Developer Zone today, there's this new tutorial that looks at making the move from PHP4's object-oriented programming up to the "more complete obejct model of PHP5" - specifically with the Decorator design pattern.   While working on a project I realized one particular solution was a pretty good way to demonstrate the decorator design pattern together with some of PHP5's features, including abstract classes, interfaces, type hinting, the final keyword and the visibility of properties and methods. This article is intended for those of you who, like myself, are moving from object-oriented programming, including some use of design patterns, in PHP4, to the more complete object model of PHP5.   He sets up a scenario about the development of an online pizza ordering system to show how to "decorate" a pizza with each of the toppings on a list (instead of having to list out every pizza in every possible topping combination). Of course, all of the code is included and explained so you understand exactly what's happening. Finally, there's a demonstration of its usage - a simple call that grabs the stock level/name/cost of each of the items in stock (pizza combinations).
334117
Sean Coates has posted a new article today about one of the features that will be included in the next major release of PHP (5.3) - late static bindings.   Late Static Binding (LSB) is a topic that's been brought up numerous times in the past three years in various PHP development discussion circles (and we're finally getting it in PHP 5.3)Ã¢Â"but what does it really do, and why should you care? Here's a simple practical example of how it can greatly simplify your code's design.   He shows its usefulness in an example of how it works, letting classes/objects access static methods, constants and properties of inherited classes (besides their own). His example (using beer, of course) shows how an extended class (Ale) can reference the constant (NAME) in the parent class (Beer). Thanks to a new keyword in PHP 5.3 - "static::" - helps define the difference even clearer.   Check out the rest of the article for a more practical usage too.
552896
DevShed has posted the next part of their series looking at handling errors thrown by the __autoload functionality of PHP. This time they enhance their previous method and allow for custom error messaging.   In this last article of the series I'm going to introduce some additional modifications to the current signature of the "__autoload()" function to make it throw exceptions that display more useful error messages.   They start by setting up the application to have something to build from (a series of PHP scripts). They add on the exception handling to throw the custom error (the "class not found" they mentioned).
616068
Continuing on with their look at the Factory Pattern (part one), DevShed has part two posted - a look at applying what was learned previously into a simple cookie-handling and file manipulation script.   At this stage you should have a more accurate idea of how to include the factory pattern into your own PHP applications, at least at a very basic level. But don't you worry because this scenario is going to change quickly, since in this second tutorial I'm going to teach you how to take advantage of the capacity offered by the pattern to create objects that are capable of saving data to different locations, including files and cookies.   The tutorial starts off by creating the classes needed to save strings and objects based off of the abstract DataSaverFactory class. On top of this, they build the classes to save the cookies and work with the files using the Factory objects.
418285
Apparently PHP5 RC3 is going to be the last release candidate. This is supposed to be coming out at the end of this week, so PHP5 will probably be released next month.  It's a bit like looking through a window into a candy store. The sweetener I most look forward to is the improved object assignment semantics.
526550
DevShed wraps up their series on using the Tidy extension with this last tutorial showing methods of tracking parse errors with the help of the library.   So, the question that comes up is the following: what is the next step? Well, from a PHP developer's point of view, tracking all the errors that occurred when parsing a concrete (X)HTML string might be quite useful. Therefore, in this final tutorial of the series I'm going to cover some new functions bundled with the Tidy extension which are designed to show you the potential errors raised when interpreting (X)HTML data.   The tutorial shows how to use the tidy_get_error_buffer, tidy_access_count, tidy_error_count and tidy_warning_count functions to search through your code and handle whatever errors (and error data) that might come up.
125329
Continuing on in their series of working with stand alone PHP scripts, DevShed has posted this third and last part looking at the creation of a basic script you can use to monitor your server (an excerpt from Advances PHP Programming by George Schlossnagle).   Last week, we continued our discussion of PHP standalone scripts with child processes and more. This week, we conclude our discussion and bring together what you've learned.   They start with the creation of a very basic daemon, including permission restrictions. They then modify this heavily to support the monitoring of processes through various parameters like frequency, status_time, and a description of the service. They then create the full example script and show the usage by checking to see if a URL passed in can be opened.   They also include, as a bonus, another more useful script that will email someone when the specified service goes down (still a HTTP check, though).
740094
In his travels as a PHP developer, Jamie Wong has gathered some helpful debugging tips that are shared in this latest post to his blog.   Here are some bugfixing rules and tips Iâve learned working all these years with PHP. I emphasize mostly on fixing bugs than preventing them, which is another subject worth of its own article. Iâve moved to Rails, but I wanted to finish this post as a farewell and thanks to every article and documentation that was useful to me. Hope this is useful to you too.   Topics covered include:  Assume nothing Turn Error Reporting to show all errors Read the error message Understand the bug "Scooby-Bug, where are you?" Get as much information as possible  Each has some explanation below it and, in some places, a bit of code to clarify the point.
494480
DevShed charges right ahead with its emphasis on design patterns in PHP with a new start of a new series today that looks at the Flyweight pattern.   Among the considerable variety of structural design patterns that can be implemented with PHP 4 (and PHP 5, by the way), there's one in particular that deserves special attention. It's easy to apply in the context of a given web application, and it offers remarkable functionality when it comes to preventing the unnecessary instantiation of different classes. This two-part series covers that pattern.   As they explain, the Flyweight pattern helps to keep your code light and simple by preventing the instantiation of unneeded objects and resources. They go with a HTML form example, illustrating how to prevent a submit button or an input button's class to be reinitialized every time a new form field is needed.
94499
Nefarious Designs continues their object-oriented PHP series with part four posted today, a look at some of the new features that PHP5 brings to the table.    After a welcome break, over the late summer public holiday here in England, here's the final part in my object-oriented PHP series. Sorry about the rather extended pause since "Part 3: Taking Relationships Further".   Having already looked at definition, relationships and taking those relationships further, I'm going to look at how PHP5's new Object Model introduces more advanced functionality.    In this latest part they look at clas constants, abstract classes, object interfaces, and magic methods (including overloading).
197002
On the SitePoint PHP blog today, Troels Knak-Nielsen has written up an article that talks about dependencies in your applications - those little interconnections your code relies on to do more with less.   In lack of better words, I'll call this compositional programming style. It's a style which is usually more prevalent with experienced programmers. [...] There is, however, a dark side to composition - dependencies.   He starts with a definition to bring everyone up to a level field then moves on to how their used (through a "global symbol" or directly passed in) and how they can "leak" if you're not careful.    To help protect you and your code from any kind of damage down the line, Troels suggests making a container to keep objects where they need to be. He even includes an example with namespace support to make things even easier down the road.
660553
DevShed continues their series looking at connecting a PHP5 script to the powerful Yahoo! search backend with part four of the series today. This part focuses on reworking some of the previous examples to make them more modular using custom defined functions.   Logically, these examples can be really useful for learning the basic concepts surrounding the use of these search services, but undoubtedly, it's necessary to modify and improve their source code to make it more compact and completely reusable.   They start the overhaul with the web search (complete with example results) then push on to the video and image searches and work them over the same way.
724182
In this new tutorial from DevShed, they demonstrate the use of a handy little bit of functionality to help keep your code (and markup) clean - Tidy.   Now that you know that the Tidy (X)HTML formatting/correcting application can be called directly from your own PHP 5 scripts, over the course of this series, which is comprised of three friendly tutorials, I'm going to walk you through using the bunch of useful functions included with this library.   This tutorial (part one) talks about the parsing of (X)HTML strings and using the tidy_clear_repair, tidy_parse_file and tidy_repair_file functions to handle the cleanup of (X)HTML strings and files automatically.
376184
DevShed starts off another design patterns series with this new article introducing the Mediator class pattern - a method to keep things up to date and synchronized in your PHP application.   Well, in this case, the synchronization between a group of PHP classes can be made by implementing a useful pattern widely known as "mediator." In short, when the mediator pattern is applied, there's a single class that implements the logic required to keep all the other classes completely synchronized with each other. This means that not only will all the modifications introduced by one class be reflected in the others, but that those changes will be performed via the interface of the mediator class.   They Apply this pattern with their traditional example of working with files - this time the class will handle the communication (and syncing) between two file handling objects. They add a file handling class on to the back end and apply them both in an example that lets you manipulate the data inside both files at the same time.
84867
Tobias Schlitt has a great (long) post responding to a proposal made on the php.internals mailing list for the inclusion of "taint mode" in upcoming PHP versions.   Tobias starts with an overview of what "taint mode" is so that everyone's on the same page. His example involves the incoming and outgoing data usually involved in an application and how the incoming can be the most problematic when it comes to the values inside. This is where taint mode can come to the rescue. At its most basic level, it's a method for, assuming everything coming in is "tainted", creating a mechanism to automatically clean the data before it's even touched.   With the basics down, Tobias looks back to the proposal for a few additional comments. He considers the proposal a great way to introduce the functionality to the language. There are some draw backs he mentions, though, including the additional overhead of working through every inputted value.   Overall, I think this whole thing would be a great addition to PHP and I hope this could come for 6.0. What do you think?   You can also check out some other opinions on the matter:  "Tainted mode" pour php on the Kamelot Blog
235064
DevShed has posted the first part of a two part series today looking at the use of static members and methods in classes in your PHP5 scripts.    Static properties and methods can be quite useful in a range of situations, not merely for constructing a Singleton class. This article, the first in a two-part series, introduces the basic concepts of static properties and methods, using plenty of hands-on examples.   Hopefully, by the end of this series you should be equipped with a decent knowledge of how to include static members and methods within your PHP applications with minor difficulties.    They start with a simple example of using both in a class before moving on to using the Singleton pattern working up to making a Factory for creating static objects.