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

Brandon Savage:
The value of design patterns
October 21, 2013 @ 12:48:37

Brandon Savage has a new post today talking about the value of design patterns with his response to another post. He tries to put the emphasis back on making good OOP code instead of worrying too much about the actual design pattern.

Anthony [Ferrara] makes some great points in his article, and I highly encourage you to read it. But I want to address the perspective that he puts forward, which is that worrying about design patterns is less important than worrying about writing great object oriented code.

He relates design patterns to the sentence structures you learn when learning a new (spoken) language. He suggests that, while they're a good way for developers to communicate, they shouldn't be the only emphasis. When a developer becomes more fluent in a language, the patterns should become less important but are still a good structure for good development practices.

0 comments voice your opinion now!
oop designpattern value opinion fluent language

Link: http://www.brandonsavage.net/the-value-of-design-patterns/

Procurios Tech Blog:
Autocompleting a lot of parameters
October 16, 2013 @ 11:14:05

Pim Elshoff has a recent post on the Procurios tech blog looking at autocompletion on function calls and an alternative to the "too many parameters" problem.

Some methods have many parameters. Sometimes they start out like that, sometimes they grow like that over time. Even though a maximum of two parameters is preferable, configuration for a method that does a big thing is difficult. Take curl for example; curl has a lot of options and so several wrappers around curl have arisen to deal with configuring it in a more humane manner. How can we keep the clutter of many parameters as low as possible, while maintaining autocompletion?

He gives an example of a function that takes too many arguments and how it's difficult to read (and remember the right order/types to give). He does mention one way that's sometimes used - arrays - but you lose typing checks with that. His best recommendation is to use a fluent interface instead. Not only does it make it more readable but it also works with the autocompletion in most IDEs.

0 comments voice your opinion now!
autocomplete parameters suggestion array fluent interface

Link: http://tech.procurios.nl/archief/2013/10/11/Autocompleting-a-lot-of-parameters

WebSpeaks.in:
Learn Simple Method Chaining in PHP
February 22, 2011 @ 11:09:13

On WebSpeaks.in today there's a recent post that introduces you to something more and more applications are using - especially frameworks - method chaining in PHP OOP apps.

In this article we will learn an advanced OOPS programming concept in PHP known as Method chaining. If you have worked on PHP frameworks like Zend, Magento or CakePHP, you might have noticed a very convinient style of accessing methods of different classes. [...] This type of programming technique is known as method chaining. If you are thinking how is it possible to perform this chaining, then don't worry. Today we will learn this fancy concept.

They create a simple class, a Person, and show the difference between calling several methods on the created object versus a method chained example that calls all three, making updates to the object itself ($this). There's also a bit more complicated example with three different classes in the mix.

0 comments voice your opinion now!
method chaining tutorial object fluent


Mark van der Velden's Blog:
PHP Quiz part 4
November 02, 2010 @ 12:05:46

If you were a fan of the PHP quizes that Mark van der Velden has posted in the past, you'll be happy to know he's come back with part four of the series after a bit of a hiatus.

It has been a while, but here is part 4 of the PHP Quiz series! A few questions to crack your brain about, or perhaps you know them all? Try them and find out! Also do read the idea behind these quizzes, here: The PHP Quiz series

In this quiz he tests your knowledge of class visibility, fluent method handling, class extension, strptime and a tricky "for" loop. Take the quiz and see how you do.

0 comments voice your opinion now!
quiz fluent visibility strptime extension


Jani Hartikainen's Blog:
Using a builder to construct complex classes
April 02, 2009 @ 12:58:28

If your code is getting more and more complex all the time and you find yourself creating a similar group of objects over and over, you might check out Jani Hartikainen's latest advice and create a "builder" around them.

Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters. [...] Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters.

His example is a "message builder" wrapper that lets you specify the receiver, sender and message and inject them into a to() method call (with a fluent interface). He shows how to make sure that the object you need (the message object) is always complete.

0 comments voice your opinion now!
fluent interface builder class complex tutorial


ProDevTips Blog:
Fluent Arrays and Strings in PHP - Adding JSON and more
July 17, 2008 @ 09:32:26

Henrik continues his look at fluent arrays and strings in PHP with this second part of his series, adding JSON functionality into the mix.

Recently I've had the need to extend the interface further, among other things with JSON support. I've used code published by Nicolas Crovatti to do this.

His example shows how the script works to plot out some points for a table of stats. He follows this with an in-depth look at the different methods making up that fluent call (apply2Field, fill_ret, sum and plot). These make the array that can then be passed off to PHP, using json_encode to make an easy-consumable JSON message out of the results.

0 comments voice your opinion now!
json fluent array string php5 tutorial jsonencode


ProDevTips Blog:
Fluent Arrays and Strings in PHP
June 23, 2008 @ 07:57:18

On the ProDevTips blog, Henrik has written up an extensive tutorial with plenty of code examples on working with something inspired by a few other languages - fluent arrays and strings.

I've been working some with jQuery and Ruby lately, as you might know they both have very neat fluent interfaces for writing short and easily understandable code. Especially Ruby's array and string handling should be something that can be done in PHP so I started googling. [...] It's probably very possible that what I'm looking for is already part of some PHP framework or such but I didn't want to spend more time looking than being productive.

Based on some Ruby examples, he defines a set of functions that can be use to create these fluent interfaces to the common PHP variable types (contained in a class for easy use). The entire source can be downloded here.

0 comments voice your opinion now!
fluent string array class source download tutorial


Zend Developer Zone:
Designing Klingon Warships Using Behaviour Driven Development
February 11, 2008 @ 15:34:00

The Zend Developer Zone has another new tutorial from Padraic Brady talking about testing your applications (i.e. unit tests). In this new article, he expands on his previous one and dives a bit deeper into the behaviour-driven development process.

In this article, I introduce a TDD related practice called Behaviour-Driven Development which has been gathering attention for over a year and gaining converts (like me!).

He briefly covers what BDD is and how it can be used to solidify code against issues that might come up down the road (and how it compares to test-driven development). Some sample code/tests are included to give you a better idea of how it all fits together - a set of scenarios for any given "story". True to the title, Padraic writes his tests around the construction of a Klingon Bird of Prey ship.

0 comments voice your opinion now!
birdofprey behavious driven development unittest fluent plain english


Alex Netkachov's Blog:
PHP fluent API tips
October 29, 2007 @ 07:57:00

In response to Travis Swicegood's post about fluent APIs, Alex Netkachov has added some of his own examples to the topic from the Zend Framework and the popular Javascript library, jQuery.

In his recent post Travis Swicegood is talking about the "Fluent API". This kind of API is very popular in scripting languages and I use it during my work with Zend Framework or jQuery projects. Another good example of such technique is Document Object Model API.

His examples show the method chaining that's the hallmark of fluent interfaces. Unfortunately, there's no good way to just make an object and call a fluent interface on it in PHP, so Alex suggests a simple little wrapper (that just returns the object) to make it easier.

0 comments voice your opinion now!
fluent api tip zendframework jquery wrapper object fluent api tip zendframework jquery wrapper object


Paul Jones' Blog:
Brief Intro to Solar_Http_Request and Response
July 17, 2007 @ 08:42:00

Paul Jones gives readers a quick overview of two of the components in the Solar framework in a new post to his blog today - the Solar_Http_Request class and it's opposite, the Solar_Http_Response class.

As I noted in an earlier post, Solar how has classes to represent simple HTTP requests and responses.

The Solar_Http_Request functionality is only for making requests, but uses adapters to make it easier to swap out the connection method later on - plus it's fluent. He includes an example of it in action, calling a remote page with a GET, POST and a customized request (including special headers)

The other side of the equation, Solar_Http_Response allows you to set all of the response information manually (again, fluently) to make custom responses simple.

0 comments voice your opinion now!
solar solarhttprequest solarhttpresponse fluent solar solarhttprequest solarhttpresponse fluent



Community Events





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


opinion introduction list configure podcast framework unittest code testing developer install series interview threedevsandamaybe release language laravel wordpress refactor community

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