Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matt Stauffer:
Implicit route model binding in Laravel 5.2
Dec 18, 2015 @ 15:34:53

Matt Stauffer has continued his series looking at the new features of Laravel v5.2. In this new article he talks about the addition of implicit route model binding. This is a bit more fancy term for the ability to link models to routes and tell Laravel they're related.

If you've never used it, Laravel's route model binding has been around for a while, but Laravel 5.2 is about to make it even easier. [...] In your route service provider, just teach the router: $router->model('shoe', 'AppShoe'); That means, "any time I have a route parameter named shoe, it's an ID representing an instance of AppShoe". [...] In Laravel 5.2, it's even easier to use route model binding. Just typehint a parameter in the route Closure (or your controller method) and name the parameter the same thing as the route parameter.

He includes code examples of the "old way" to do it with model functionality inside the route and the "new way" of linking the model to the route. This allows you to auto-magically have a valid model instance once the route is called. He also shares some of the little known features of this model binding including using closures in bind() calls and changing the "route key" away from the "id" column.

tagged: model route binding laravel feature implicit feature v52

Link: https://mattstauffer.co/blog/implicit-model-binding-in-laravel-5-2

DZone.com:
Closure Object Binding in PHP 5.4
Oct 28, 2011 @ 13: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.

tagged: object binding support tutorial template example

Link:

Eric Hogue's Blog:
Late Static Binding
Apr 22, 2011 @ 14:14:34

Eric Hogue has a recent post to his blog looking at one of the more tricky aspects of the latest versions of PHP (the 5.3.x series) - late static binding. In a nutshell, late static binding (LSB) lets static classes and methods work more correctly than before. Eric gets into a bit more detail than that:

It came out almost 2 years ago, but it to me that many programmers around me have no idea about it. Myself, I have learned about it around 6 months ago. The PHP documentation defines late static binding as a way to "reference the called class in a context of static inheritance." This definition didn't really help me the first time I read it. Fortunately, there are more explanations in the documentation, and there are good examples. If you haven't, you should read it.

To clarify, he includes a code snippet showing the use of the "static" keyword to correctly reference a static method. He also includes in interesting bit about when's a good time to use it.

tagged: late static binding lsb tutorial explaination

Link:

Alexey Zakhlestins' Blog:
GObject for PHP (new bindings project)
Feb 24, 2011 @ 14:25:23

In a new post Alexey Zakhlestins talks about a project he's been working on, a part of the split up with PHP-GTK out into separate projects. His part of the group is GObject with has now been moved over to github.

This new PHP extension is called "GObject for PHP", so, my main concern, obviously is building comfortable bridge between GObject objects and PHP's objects. It starts to work, but there's a lot of stuff to be done. Please join the project, if you are interested. We need more hands!

He describes some of the features already in the library - counterparts for parts of the current GObject world in PHP including GType, GSignal and GParamSpec. This is all on the master branch. In his "introspection" branch he's working on the introspection idea the GNOME community has been working towards too.

tagged: phpgtk gobject binding github master introspection

Link:

C7Y:
Late Static Binding: a practical example
Feb 12, 2008 @ 21:52:36

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.

tagged: late static binding tutorial example beer

Link:

Joshua Thompson's Blog:
Return to Prototype Based Programming in PHP
Oct 31, 2007 @ 21:38:00

Taking full advantage of the upcoming features in the PHP 5.3.x series (and in PHP6 for that matter), Joshua Thompson has come up with a way to accomplish some prototype-based programming in a PHP application:

With the implementation of the get_called_class() function in PHP, prototype based programming in PHP is possible. The new function is in both PHP5.3 and PHP6 snapshots. So, I went back to the drawing board and came up with a fully capable class. The $this keyword is usable, as well as being able to use the self, parent, and static (new with the late static binding patch) keywords.

Prototype-based programming is (basically) a method where classes aren't prebuilt. Instead they are created on the fly based on other objects and interfaces. Joshua's post is a huge code dump of a prototype class and an example of it in use, dynamically creating two methods and making the three objects available.

tagged: prototype programming object clone interface namespace static binding prototype programming object clone interface namespace static binding

Link:

Joshua Thompson's Blog:
Return to Prototype Based Programming in PHP
Oct 31, 2007 @ 21:38:00

Taking full advantage of the upcoming features in the PHP 5.3.x series (and in PHP6 for that matter), Joshua Thompson has come up with a way to accomplish some prototype-based programming in a PHP application:

With the implementation of the get_called_class() function in PHP, prototype based programming in PHP is possible. The new function is in both PHP5.3 and PHP6 snapshots. So, I went back to the drawing board and came up with a fully capable class. The $this keyword is usable, as well as being able to use the self, parent, and static (new with the late static binding patch) keywords.

Prototype-based programming is (basically) a method where classes aren't prebuilt. Instead they are created on the fly based on other objects and interfaces. Joshua's post is a huge code dump of a prototype class and an example of it in use, dynamically creating two methods and making the three objects available.

tagged: prototype programming object clone interface namespace static binding prototype programming object clone interface namespace static binding

Link:

Mike Lively's Blog:
Late static binding....sorta :/
Sep 27, 2007 @ 17:58:00

Mike Lively is happy about one thing - that late static binding (definition) has been committed and will be included with PHP 5.3. Unfortunately, he has a downside too:

The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.

He talks about the original intention of the functionality (flexible inheritance for static methods/properties/constants) and how it was implemented, but with one small issue - that "static will ALWAYS return the 'resolved' name of the class used to call the current function". He illustrates with a code example showing an extended class returning a static property.

He also mentions two suggestions to help fix this issue:

  • setting the behavior of parent:: such that it forwards the calling class through the next function call.
  • introducing another scope [...] using a new keyword so parent:: could remain the same
tagged: late static binding patch missing functionality parent inheritance late static binding patch missing functionality parent inheritance

Link:

Mike Lively's Blog:
Late static binding....sorta :/
Sep 27, 2007 @ 17:58:00

Mike Lively is happy about one thing - that late static binding (definition) has been committed and will be included with PHP 5.3. Unfortunately, he has a downside too:

The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.

He talks about the original intention of the functionality (flexible inheritance for static methods/properties/constants) and how it was implemented, but with one small issue - that "static will ALWAYS return the 'resolved' name of the class used to call the current function". He illustrates with a code example showing an extended class returning a static property.

He also mentions two suggestions to help fix this issue:

  • setting the behavior of parent:: such that it forwards the calling class through the next function call.
  • introducing another scope [...] using a new keyword so parent:: could remain the same
tagged: late static binding patch missing functionality parent inheritance late static binding patch missing functionality parent inheritance

Link:

Etienne Kneuss' Blog:
Late Static Bindings Explained
Sep 07, 2007 @ 19:26:00

Etienne Kneuss has a new article posted about and introducing a feature that will be implemented in PHP6 - late static bindings.

Late Static Binding (LSB, yes, not LSD) is an OO feature that is meant to be implemented in PHP 6, and maybe even backported to PHP 5. This article will describe what LSB is, what problems it's supposed to solve and how. The patch this article talks about can be found here: late_static_bindings_take6.patch

Etienne explains what they are and includes several code examples to show how they'll work. There's also a mention of "edge cases" where special circumstances might cause the script to fall back on the "magic" functions (__get, __post, etc).

tagged: late static binding php6 explain introduction example late static binding php6 explain introduction example

Link:


Trending Topics: