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

Vance Lucas:
Introducing Bullet The Functional PHP Micro-Framework
December 21, 2012 @ 09:02:00

Vance Lucas has a new post to his site sharing at a project he's been working on, a micro-framework for PHP that takes a functional approach to its structure (and the structure of the apps you can make with it), Bullet.

Bullet is a new PHP micro-framework with a unique functional approach to URL routing that allows for more flexibility and requires less verbosity than the more typical full route+callback approach found in other micro-frameworks. The main problem with most micro-frameworks and even full-stack MVC frameworks that leads to code duplication is that the callback or method executed to perform the action and respond to the URL route lives fully within its own scope. This means that you are forced to repeat a lot of setup code across URL route handlers that load the same resource, authorize it, etc.

He illustrates with an example of a GET/DELETE to the same routes and having to create multiple handlers for each. He restructures this with Bullet and shows how it can nest callbacks inside of handlers to make for simpler routing. It also scopes down requests and gets more fine grained as you nest, making it easier to create reusable handlers (like in other files). If you're interested in finding out more about Bullet and its structure, you can find it in the project's main site.

0 comments voice your opinion now!
bullet microframework nested functional scope routing


PHP Tip-a-Day:
PHP Tutorial Convoluted Code - Combining Ternary Operators and Anonymous Functions
May 30, 2012 @ 10:09:40

On the PHP Tip-a-Day site Greg Bulmash shares a bit of "convoluted code" that could potentially cause confusion in the future maintenance of your application - combining ternary with anonymous functions.

Following on yesterday's post about chaining if statements without brackets on a single line, I tried to explore other ways to perform this "test if the variable is set, then do a comparison if it is" logic. I created one of the most convoluted lines of code I've ever written. It's no SQL join that spans 5 whiteboards, but it's pretty unreadable.

His example uses not just one ternary comparison, but nested ones with the anonymous function as the first condition. He points out that, if you're not careful with this method and make both sides anonymous functions, you could be in for a "cannot be converted to string" error on the closure side.

I'm sure there might be a very good reason to put two anonymous functions in a ternary operator, but I can't think of one at the moment. It's a fairly ugly proposition.
0 comments voice your opinion now!
ternary nested anonymous function closure compare


Refulz.com:
Traits in PHP - Multiple and Nested Traits
May 28, 2012 @ 15:16:29

On the Refulz.com blog there's a new tutorial posted looking at traits (and nested traits) in PHP including examples of them in use and how to create your own.

Traits is a good new addition to PHP language. In our series about the new features of PHP 5.4, we reviewed the concept of Traits in PHP. The introductory article talks about what the traits are and what is the general syntax of Traits in PHP. The second article attempts to explain why we need traits.

The tutorial shows you how to define a custom trait use things like abstract methods, nesting them by making them "users" and how to use multiples at the same time (comma-separating).

0 comments voice your opinion now!
traits multiple nested tutorial abstract


DevShed:
Using Nested Views with CodeIgniter
April 03, 2009 @ 07:56:01

The "Introduction to CodeIgniter" series continues on DevShed with this new article, a look at nested views in their sample application.

In this third chapter of the series I'm going to discuss one that bases its functionality on the loader class that comes bundled with CI. [...] By means of this method, it is very simple to replace in one single step all the variables included into multiple views with actual data. Therefore, in the next few lines I'm going to discuss how to use it to generate a dynamic web document, which will display some database contents.

After a quick review of loading views sequentially, they look at the new stuff - a "master view" that can load multiple other views inside. To pass information into this master view, they use the "$this->load->vars()" method included in the framework.

0 comments voice your opinion now!
nested views codeigniter framework load variables


Patrick Allaert's Blog:
Readable PHP code #1 - Return ASAP
October 14, 2008 @ 11:14:42

Patrick Allaert has made this recent post to his blog looking at something that a large group of PHP developers seem to forget about - readable PHP code. Specifically, he mentions the "return as soon as possible" mentality.

This is the first article of a series I will dedicate to tips to write PHP code that is easier to maintain, review, refactor,... These tips may be applied for other languages but are mainly focused on PHP. The first one could be entitled as "return as soon as possible.

He compares a code example - simplifying multiple if/elses, replacing the need for multiple nested evaluations that make the code harder to read. Check out the before and after to see how it helps the flow.

0 comments voice your opinion now!
readable return asap refactor ifelse nested


DotVoid.com:
Reordering nested sets using PHP and Javascript
September 14, 2007 @ 14:44:00

On the DotVoid blog today, Danne Lundqvist has posted about a problem he had - creating parent/child style data and displaying it as nested sets with the combination of PHP and Javascript. He outlines two different methods but only chooses one to run with.

The first method is "adjancency", a method that involves storing a parent ID in each node and recursing to find the related ones. He goes with a different solution, however - a "nested set". This method stores the data in terms of where it's located on the tree (layers from right, layers from left, etc).

Last night I was working on an application that display a full tree where the user must be able to to drag and drop nodes to reorder the tree. The problem is that it is much more difficult to insert or reorder the tree using the nested set model.

This was particularly effective in solving his problem, making a reogranizable listing that could be manipulated via a Javascript interface (the MooTree script from MooTools). Hi sPHP solution is included.

4 comments voice your opinion now!
javascript order list nested set adjancency method model javascript order list nested set adjancency method model


Felix Geisendorfer's Blog:
Cake 1.2's Set class eats nested arrays for breakfast!
February 28, 2007 @ 10:04:00

Felix Geisendorfer has a great functionality note that CakePHP users might want to check out. It's related to the Set class and how it handles nested arrays.

So far this has been a little dark spot for me in the core and from my previous quick looks at the class I've never been quite able to figure out what it's exact purpose was. Until now all I knew was "well it's probably some fancy array manipulation code that is somewhat obfuscated and undocumented". Oh boy, I wish I had spent more time on this earlier. It's probably one of coolest new features in 1.2 and nobody realizes it.

He starts with a simple example of how the class works with a nested array of user information. Normally, you'd loop through the array and append the values you'd need to another array (like the user's name), but with Set, it's as simple as calling the static "extract" method with the "path" to what you want out of the array. A simple one-line replacement for a (normally) three to four line bit of code.

He gives a few other examples using this same user information, grabbing various results and includes one at the end that is very nice indeed - pulling in an XML document, running it through a simple xmltoArray function and pulling out the titles in a few easy lines.

0 comments voice your opinion now!
set class cakephp nested array extract combine xml parse set class cakephp nested array extract combine xml parse


Tobias Schlitt's Blog:
Avoid an endless pifall
February 15, 2007 @ 09:03:00

Tobias Schlitt has provided a helpful hint for developers working with lots of objects, methods, and singleton patterned functionality to keep out of the same trouble he faced.

During my current exam phase I'm working on some tiny private project to relax after learning. In there I'm using a main controller class, which implements a singleton pattern and initializes several sub-controllers while being created. The singletons purpose is, that the other controllers can access to main controller and its functionality whenever they need, without storing a reference each.

The problem with the code (he gives snippets) was a recursive loop that was suddenly appearing. He finally tracked it down to a constructor in another class that was accessing the main controller's constructor. The issue was that the constructor was never finishing up, so a valid instance wasn't returned, so the whole thing started all over again.

0 comments voice your opinion now!
singleton pattern object nested constructor controller singleton pattern object nested constructor controller



Community Events





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


library symfony laravel opinion artisanfiles version podcast series tool security introduction release framework voicesoftheelephpant list conference interview community language composer

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