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

Mathias Verraes:
Named Constructors in PHP
June 13, 2014 @ 09:42:15

Mathias Verras has a new post to his site about an idea he calls "named constructors". This method uses static factory methods to simulate the idea of a constructor and initialize the object.

PHP allows only a single constructor per class. That's rather annoying. We'll probably never have proper constructor overloading in PHP, but we can at least enjoy some of the benefits. Let's take a simple Time value object. Which is the best way of instantiating it? The only correct answer is "it depends".

His example shows the typical constructor creation with variable arguments, but points out that this can get messy quickly. His other method, the factory methods as "constructors", can make for a cleaner interface and makes the class more flexible. They make the object able to be initialized with different types of values and even satisfies the Single Responsibility Principle. He goes through a few examples using his "Time" class, showing how different "constructor" methods can be used to handle inputs ranging from a normal hour/minute format out to a "from minutes since midnight" value.

0 comments voice your opinion now!
named constructor factory method static tutorial time

Link: http://verraes.net/2014/06/named-constructors-in-php/

Phil Sturgeon:
Named Parameters in PHP
September 02, 2013 @ 10:52:40

in a new post to his site Phil Sturgeon talks about a new (old?) proposal to introduce named parameters into PHP.

Named Parameters for PHP is not a new conversation. It's reared its head several times - so much so that the named parameters RFC says: "Since the topic continually gets re-raised, and now PHP has an RFC process, the discussion should be recorded in an RFC (Note this is yet to be done) so the same arguments don't have to be revisited."

He notes the negative attitude that seems to currently be shown in the RFC and has made the offer to rewrite it to be more impartial to the subject at hand. In the comments of the post there's also some feedback about the different syntaxes and varying levels of support for the proposal.

0 comments voice your opinion now!
named parameter language feature rfc rewrite

Link: http://philsturgeon.co.uk/blog/2013/09/named-parameters-in-php

PHPClasses.org:
Lately in PHP Ep. 6 - Unusual Site Speedup Techniques, Named params & Annotations
November 01, 2010 @ 08:29:46

On the PHPClasses.org site today they've posted the latest episode in their "Lately in PHP" podcast series - "Unusual Site Speedup Techniques debate, Named parameters and Annotations".

In this episode, Manuel Lemos and Ernani Joppert discuss several unusual site speedup techniques presented in recent articles of the PHPClasses site blog. They also discuss the (non-)inclusion of new PHP features discussed by PHP core developers like having named parameters in function calls and the support of Java-like annotations in PHP code.

To listen you can either use the in-page player, grab it from iTunes or just download the mp3. Complete show notes and transcript are also included in the post.

0 comments voice your opinion now!
podcast latelyinphp speedup technique named parameter annotation


Stoimen Popov's Blog:
preg_match Give Names to the Matches
July 06, 2010 @ 11:01:48

In a quick post to hos blog today Stoimen Popov points out a handy feature of the preg_match function in PHP (in PHP 5.2.2 and higher) to be able to name the results of the regular expression match.

In PHP 5.2.2+ you can name the sub patterns returned from preg_match with a specific syntax. [...] This is extremely helpful, when dealing with long patterns. [...] Although it may look difficult to maintain, now you can simply name the sub patterns of preg_match and to call them with their associative array keys. This is more clear when writing code and it's definitely more maintainable.

The key is to use a special syntax as a part of the expression's pattern. This replaces the numeric keys of the matches with values you define, making it simpler to use the results (instead of having to work with numbers that don't match much of anything). Code and expression examples are included.

0 comments voice your opinion now!
named result match pregmatch regularexpression


Jamie Rumbelow's Blog:
Named Scopes with CodeIgniter
January 07, 2010 @ 12:20:20

Jamie Rumbelow has proposed an idea to help simply some of the interactions your CodeIgniter application can have with your databases by using named scopes.

Named scopes are a really powerful feature of models - they allow you to define a clean, concise syntax when performing queries within your models - and best of all, are really easy to utilize in CodeIgniter. The main principle of a named scope is that you create a method that, combined with method chaining, allows you to add details to your query (generally additional WHERE clauses).

He shows two "before and after" examples of multi-line requests condensed down by making a custom model layer with methods containing the commonly used portions of the database calls and returning the "$this" object so it can be used for chaining.

0 comments voice your opinion now!
named scopes codeigniter framework


Mind Tree Blog:
Friendly URLs in PHP why do you care?
June 26, 2008 @ 10:26:59

This new post from the Mind Tree blog (at hurricanesoftware.com) asks the question "why do you care about friendly URLs in PHP applications?"

Nice URLs, readable URLs, search-engine-friendly URLs. Different names same deal. [...] Turns out this isn't all that hard with PHP - in fact it can turn into something that's very useful from more than just a readability viewpoint.

He shows how to use mod_rewrite and an .htaccess file to automatically grab the request and map it to the right place. Then, the PHP script looks at the incoming data and pushes the correct page back out to the browser. He's also included some modifications to the original idea that allow for numeric grouping and named groups for rewriting content.

1 comment voice your opinion now!
friendly url modrewrite htaccess group named numeric


Codewalkers.com:
Named Arguments Discussion on PHP Mailing List
January 17, 2006 @ 06:54:21

On Codewalkers.com today, there's a note about an interesting bit of discussion going on over on the PHP mailing lists dealing with "named arguments".

There is an interesting discussion going on in the internals list on whether or not to have named arguements in php6. The start of the discussion is here with a break off thread here.

Named arguments would allow you do to something like this:

testFunc(name:"test",vals:"stuff")

Naming the items in the code and allowing them to be accessed via one variable internal to the function. There are some pretty good arguments on both sides of things, but it still doesn't seem like it's going to be taken much further than this...

0 comments voice your opinion now!
named arguments discussion mailing list named arguments discussion mailing list



Community Events





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


framework update podcast tips list api zendserver language package community deployment interview opinion symfony release install laravel introduction library series

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