 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Davey Shafik's Blog: The Closure Puzzle
by Chris Cornutt January 16, 2012 @ 09:52:38
Davey Shafik has posted about an interesting find with closures in PHP revolving around an update to add "$this" access inside the closure.
However, it didn't stop there; there was also the addition of Closure::bind() and Closure->bindTo(). These methods are identical except one is a static method into which the closure is passed, the second an instance method on the closure itself. These methods both take two arguments (on top of the closure for the static version): $newthis and $newscope. What this means is that unlike the regular object model the concept of $this and lexical scope (what is in scope for the function with regards to private/protected methods inside objects) are completely separated.
He also mentions that you can change the "$this" to a different object (complex) or swapping out the object the closure is bound to while keeping "$this" the same (simpler). He mentions that it could be useful for unit testing but can have its drawbacks. He's included code to illustrate
the breakage it can cause in the PHP OOP model (with an explanation).
voice your opinion now!
closure puzzle bindto bind oop object
Gonzalo Ayuso's Blog: Runtime Classes. A experiment with PHP and Object Oriented Programming
by Chris Cornutt August 08, 2011 @ 09:17:05
Gonzalo Ayuso has put together an experiment related to the current OOP structure of PHP - a test working with runtime classes, a structure generated entirely when the script is executed and not predefined in the file.
Last week I was thinking about creation of a new type of classes. PHP classes but created dynamically at run time. When this idea was running through my head I read the following article and I wanted to write something similar. Warning: Probably that it is something totally useless, but I wanted to create a working prototype (and it was fun to do it).
His class is pretty basic - a "Human" object that echoes a "hello world" sort of message via a "hello()" method. He creates the classes inside of different test methods to ensure that his assertions are true. The tests check basic output of the "hello()" method, calling undefined methods, testing inheritance and a test creating and evaluating a dynamic function.
For something more complex, he creates a dynamic class that solves the FizzBuzz kat, a popular programming puzzle. You can find the full code for this and his other examples on github.
voice your opinion now!
runtime class experiment objectoriented oop fizzbuzz
Elated.com: Object-Oriented PHP Autoloading, Serializing, and Querying Objects
by Chris Cornutt July 01, 2011 @ 08:29:45
On Elated.com today there's the fourth part of their series looking at object oriented programming in PHP. This time the focus is specifically on autoloading classes, making objects into strings (serialized) and introspection.
If you've read all the articles up to this point then you're already familiar with the most important concepts of object-oriented programming in PHP: classes, objects, properties, methods, and inheritance. In this final (for now, at least!) tutorial in the series, I'm going to tie up some loose ends and look at some other useful OOP-related features of PHP.
He looks at each of the three topics above and includes code for things like a simple autoloader, object serialization, using sleep/wakeup and an example of using functions like get_class, get_class_methods and get_object_vars to do introspection on your classes and objects.
voice your opinion now!
oop tutorial class object autoload serialize introspection
Zend Developer Zone: SOLID OO Principles
by Chris Cornutt June 06, 2011 @ 12:06:35
On the Zend Developer Zone there's a recent post from Keith Casey about some of the basics of good OOP design, specifically in following the SOLID principles - a set of five guidelines that make code easier to manage and maintain over time.
As much as we're like to believe that "loose coupling, high cohesion" is enough, when you actually dive into the concept, you find that it's more descriptive than prescriptive. If you want to know how to actually apply these to your day to day development, you have to get into the SOLID principles which describes the five tangible aspects that "good" OO design should contain.
He goes through each of the five principles in the list, describing what they are and, for some, including a bit of sample code to make the point clearer:
- Single Responsibility Principle (SRP)
- Open/Closed Principle (OCP)
- Liskov Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
voice your opinion now!
oop principles solid example
Elated.com: Object-Oriented PHP Working with Inheritance
by Chris Cornutt May 27, 2011 @ 09:21:20
On Elated.com there's a new introduction to working with inheritance in PHP for object-oriented applications. They work through some of the basic concepts including parent/child classes, final and abstract classes and interfaces.
In this article we're going to explore the idea of inheritance in object-oriented programming, and how inheritance works in PHP. With inheritance, your objects and classes can become much more powerful and flexible, and you can save a lot of time and effort with your coding.
They start with the basics of how inheritance works and then move right into creating child classes from a parent. Their example code makes a basic forum system (just example code, not fully functioning) with administrators, members and forum creation. They use this as a base to show the method overriding and exposure with "final". The finish it off with examples of two things that can promote good application structure - abstract classes an interfaces.
voice your opinion now!
oop tutorial inheritance introduction objectoriented
NetTuts.com: Create WordPress Plugins with OOP Techniques
by Chris Cornutt May 20, 2011 @ 11:28:31
On NetTuts.com today there's a guide to help you create WordPress plugins with object-oriented code instead of procedural method. This means better encapsulation, reusability and more maintainable code.
Object-oriented code, among other things, can help organize and add reusability to your code. In this tutorial, I will teach you the basics of writing a WordPress plugin using object oriented techniques. We'll be using Dribble's API as an example for this tutorial.
They walk you through a brief explanation of OOP in WordPress plugins, setting up a shortcode, making a template tag and enabling this shortcode in the WordPress widgets. Their example grabs the latest shots from Dribble with a getImage() method that fetches the results from their REST API.
voice your opinion now!
wordpress plugin oop class dribble tutorial
Web Developer Juice: PHP Magic Functions Best Part of Object Oriented PHP - Part 1
by Chris Cornutt May 03, 2011 @ 11:57:08
On the Web Developer Juice blog there's a recent post, the first part in a series looking at one of the more handy features of the recent releases of PHP - the magic functions (some which were added in the PHP 5.x series).
There are some reserved function names in PHP class starting with __ ( double underscore ). These are __construct, __destruct, __isset, __unset, __call, __callStatic, __sleep, __wakeup, __get, __set, __toString, __set_state, __invoke and __clone. You cannot use these functions to serve your logical purpose but these are meant to be used for providing magic functionality.
They go through some of the above methods and talk about what role they can play in your code and, for some, a brief bit of code to explain how it works. This first part covers __construct/__destruct and __call/__callStatic.
voice your opinion now!
objectoriented oop magic method tutorial
|
Community Events
Don't see your event here? Let us know!
|