 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: The Liskov Substitution Principle
by Chris Cornutt January 24, 2012 @ 13:40:35
On PHPMaster.com today there's a new post from Alejandro Gervasio about a part of the SOLID development methods - the Liskov Substitution Principle - the idea that objects should be replaceable with instances of their subtypes without a change to the architecture of the application.
Even when the formal definition of the LSP makes eyes roll back (including mine), at its core it boils down to avoiding brittlely-defined class hierarchies where the descendants expose a behavior radically different from the base abstractions consuming the same contract.
He includes an example with a "deleted scene" from the Matrix depicting an attempted override of the PDO functionality with a subclass that, unfortunately, does not match the original's structure/method definitions. The problem was in the difference between the method signature for the "query" method. It help resolve situations like this he recommends creating a "contract" in the form of an interface your code can implement, forcing it to conform to a certain structure. Using this, he provides a rewrite of the "PdoAdapter" class to match the original signature
voice your opinion now!
liskov substitution principle tutorial example solid development pdo interface
DZone.com: PHPUnit_Selenium
by Chris Cornutt January 20, 2012 @ 09:12:18
On DZone.com today Giorgio Sironi has a quick tutorial showing you how to set up and use the PHPUnit_Selenium component in the latest releases of the popular testing software.
With the 1.2 release, PHPUnit_Selenium supports (basically) for the first time the Selenium 2 WebDriver API. While PHPUnit_Selenium already worked with Selenium 2, it did so only by using the Selenium 1 emulation included in the jar; now it provides an object-oriented API right natively supported in a base PHPUnit test case, shipped in PHPUnit's PEAR channel.
He includes the steps you'll need to pull it from the PEAR channel and how to set up a test case based on the PHPUnit_Extensions_Selenium2TestCase object. He gives a few examples of how to select various components on the page (via CSS selectors and XPath), assert that the right information is there and interact with forms.
voice your opinion now!
phpunit selenium install unittest tutorial example select interact
Gonzalo Ayuso's Blog: Playing with the new PHP5.4 features
by Chris Cornutt November 28, 2011 @ 08:10:51
Gonzalo Ayuso has a new post to his blog today showing some of the experimentation he's done with PHP 5.4 features like the short array syntax, calling methods through arrays and traits.
PHP5.4 it's close and it's time to start playing with the new cool features. I've created a new Virtual Machine to play with the new features available within PHP5.4. I wrote a post with the most exciting features (at least for me) when I saw the feature list in the alpha version. Now the Release Candidate is with us, so it's the time of start playing with them. I also discover really cool features that I pass over in my first review.
Code snippets are included for each example for:
- Class member access on instantiation
- Short array syntax
- Support for Class::{expr}() syntax
- Indirect method call through array
- Callable typehint
- Traits
- Array dereferencing support
He points to this other post for a complete list of what's been added in 5.4.
voice your opinion now!
feature releasecandidate traits example tutorial
DZone.com: Closure Object Binding in PHP 5.4
by Chris Cornutt October 28, 2011 @ 08:43:26
In a new post to DZone.com Mitchell Pronschinske looks at closure object binding in PHP 5.4 applications (yes, we know PHP 5.4 isn't released yet). He explains what this is an shows some sample use cases for you to consider in your development.
For the people who read PHP's NEWS file, it's no surprise - but for all who don't here's is probably one of the biggest features of PHP 5.4: Closure Object Support is back. For me it's something I missed the most, when Closures were introduced in PHP 5.3. So I'm very happy, that's finally here (or back). I'm going to tell you about the rocky road which closure object binding support had and show you some simple use cases for it.
The functionality, based on this RFC, lets you more correctly bind closures to objects instead of having to pass the objects into the closure at create time. He includes an example from a Silex framework application and an example that refactors a helper method as a part of rendering a simple template.
voice your opinion now!
object binding support tutorial template example
ZetCode.com: SQLite PHP tutorial
by Chris Cornutt October 17, 2011 @ 12:12:48
If you're in the process of prototyping a site or just need a lightweight storage tool for your application, you might look into SQLite. Fortunately, PHP has direct support for it and this great tutorial from ZetCode.com will introduce you to some of the basic concepts you'll need to get working (it's a bit older, but still very useful).
This is a PHP programming tutorial for the SQLite database. It covers the basics of SQLite programming with PHP language. There are two ways to code PHP scripts with SQLite library. We can use procedural functions or OOP objects and methods. In this tutorial, we use the classical procedural style. You might also want to check the PHP tutorial or SQLite tutorial on ZetCode.
They go through the basic installation (on a linux platform, but easily adapted to others) including changes to your php.ini and the creation and use of a first sample database. You'll find the interface very similar to some of its other RDBMS cousins with a few exceptions. They show you the CRUD basics - creating records, reading the contents of a table, updating data already there and deleting records. There's also a simple form tutorial that takes a name and gender and does the inserts.
voice your opinion now!
sqlite tutorial crud form example
NetTuts.com: The Ins and Outs of PHP Exceptions
by Chris Cornutt October 14, 2011 @ 08:44:32
On NetTuts.com today there's a new tutorial showing you the "ins and outs" of using exceptions in PHP - throwing them, handling the result and integrating them into your error handling process.
Still returning false whenever a function in your program fails? In this article, we'll learn about PHP exceptions, and how you can use them to soup up your application's error handling.
The include some of the methods you can call on your exceptions (including getting the message, code, file, line and the results of a debug_backtrace right before it was thrown). Included is code to throw exceptions, catch them with a try/catch and using error codes as return values and extending them to fit your own needs.
voice your opinion now!
exception handling throw tutorial extend example
PHPMaster.com: Array Handling Functions
by Chris Cornutt October 11, 2011 @ 08:37:55
On PHPMaster.com today there's a new tutorial introducing you to the array handling features in PHP - sorting, slicing and more.
In my previous article on PHP arrays I suggested a number of things that are tables and therefore can also be expressed as arrays. In this article I'll use a pack of playing cards to explore some of the built-in array functions most often needed by PHP programmers.
To highlight some of the array-handling functions PHP offers, I'll be using some components of Buraco - a game very popular in my part of the world and quite similar to Rummy.
In the example he represents a deck of cards with an array of values like "A", "03" and "13". This array is then looped to make the full set of 52 cards and shuffled to deal a "hand". Array functions put to use include array_rand, in_array and sort.
voice your opinion now!
array handling function tutorial example buraco card game
PHPMaster.com: Documentation Makes the World Go Round
by Chris Cornutt October 04, 2011 @ 09:03:16
On PHPMaster.com today there's a new article emphasizing something that lots of developers forget to make a part of their process when writing code - creating useful documentation to help make your code that much clearer.
If you're writing code that will be shared with others, put yourself in their shoes. Don't let your project lose potential users, community members, and possible contributors all because of insufficient documentation.
He (Matthew Turland) suggests a few things to keep in mind as you're writing up your documentation - the content is "king" (an emphasis on good descriptions/examples/use cases), open it up to external contributions using things like wikis (or even stored in the source code repository) and a focus on technical writing skills. Even the best tools out there can suffer if there's poor or no documentation.
voice your opinion now!
documentation application code opinion content usecase example technical writing
|
Community Events
Don't see your event here? Let us know!
|