 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: Using Traits in PHP 5.4
by Chris Cornutt February 09, 2012 @ 08:40:50
On PHPMaster.com today there's a new tutorial about using a feature in the upcoming PHP release (5.4) to make it easier to work with more modular code - using traits.
In this article I will discuss traits, a new feature introduced in PHP 5.4 to overcome [issues where multiple inheritance is needed]. The concept of traits itself is nothing new to programming and is used in other languages like Scala and Perl. They allows us to horizontally reuse code across independent classes in different class hierarchies.
Included in the post is example code showing what the use of a trait looks like and a method for creating a Singleton that can spawn instances of two classes. Also included are examples of:
- using multiple traits at once,
- traits made up of traits,
- the importance of order,
- aliasing to avoid conflicts,
- reflection
- and a few other features that come along with their use.
voice your opinion now!
traits tutorial introduction feature multiple inheritance
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
Zend Developer Zone: Creating Web Page Templates with PHP and Twig (part 2)
by Chris Cornutt May 05, 2011 @ 13:11:25
On the Zend Developer Zone they've posted the second part of Vikram Vaswani's look at using the Twig templating engine in your PHP applications. In the first part of the series, he introduced the tool and got started with some simple examples. In this second part, he dives in deeper to some of the advanced features.
In this second and concluding segment, I'll look at some of Twig's other features, including such goodies as template inheritance, custom filters and caching. If you enjoyed the first part of this article, keep reading to find out more about what goes on under Twig's hood, and how you can add even more power and flexibility to your templates
He looks at template inheritance, parent blocks/child templates, data filtering, the tool's "compilation cache" and working with native plugins.
voice your opinion now!
twig template tutorial inheritance filter cache plugin
Bence Eros' Blog: Using Inheritance
by Chris Cornutt December 02, 2010 @ 12:14:39
In this new post to his blog, Bence looks at how inheritance is commonly used in PHP applications and how, if not controlled carefully can be something that creates bad habits among PHP developers.
In fact I think that using inheritance all the time is a very big mistake and makes your code hard to maintain and more hard to integrate (the latter is a mistake for application codes and a fatal mistake for libraries). The main problem with inheritance is that if you use it for coupling two classes, then a very important property of the subclass is used up: it's superclass. It is taken, reserved, and it can not be used for anything else furthermore. If you want to connect your subclass to an other class using inheritance, you can't.
He recommends avoiding the typical uses of typical superclass/subclass inheritance unless what you're doing specifically requires it. Working with interfaces, abstract classes and good composition planning is a much better idea.
voice your opinion now!
abstract class inheritance opinion composition
SimasToleikis' Blog: New to PHP 5.4 Traits
by Chris Cornutt November 22, 2010 @ 09:11:09
Simas Toleikis has a new post to his blog looking at a feature that'll be included in PHP 5.4 - something developers have been wanting for a long time - traits.
As a long-time internals.php mailing list reader I am going to tell you a small secret - the first alpha release for PHP 5.4 should be just around the corner. This release is packed with some welcome new language features, usual bug fixes followed by some performance and memory management improvements. One of the noteworthy language additions are Traits - a brand new horizontal code reuse mechanism.
He explains traits as a better way to do the "kind-of" inheritance that PHP does now with parent and child classes, making it easier to reuse functionality from classes even though they don't share the same parent. With the "use" keyword (not to be confused with the "use" keyword in namespaces) you can include common functionality into class methods and even accommodate for naming conflicts and requirements.
voice your opinion now!
traits new feature internals mixins inheritance
Chance Garcia's Blog: Visibility and inheritance
by Chris Cornutt August 12, 2009 @ 09:40:20
In this recent post to his blog Chance Garcia looks at visibility and inheritance in PHP applications. Specifically, it references a question that came up on IRC about the "default" visibility for methods and the open/closed principle.
Out of the whole discussion, here is the points I got (aka understood) out of it. Please correct me in the comments if I'm off base in any way.
There's two points he makes in the remainder of the post:
- Methods should only be public when necessary.
- Private methods allow you to preserve the class' core functionality.
There's also a bit of code included to illustrate some of his points.
voice your opinion now!
visibility inheritance openclosedprinciple
Brandon Savage's Blog: Where Multiple Inheritance Will Kill You
by Chris Cornutt July 17, 2009 @ 11:19:02
In this new post to his blog Brandon Savage takes a look at multiple inheritance in PHP applications - specifically where it could "kill you" if you're not careful.
This is a fantastic way to further encapsulate and abstract your code because it means you can define some base functionality and then later on extend that class to add new functionality and even override existing functionality to make the class specific. But this concept is a double-edged sword in PHP (and all other languages).
The problem lies in methods in classes that could be overriding parents and the sort of results that instance of might return in a multiple inheritance environment. He includes code snippets both illustrating the problem and showing a suggestion for how it could be avoided.
voice your opinion now!
problem instanceof inheritance multiple
Blue Parabola Blog: Objectively Oriented
by Chris Cornutt February 18, 2009 @ 09:31:30
On the Blue Parabola blog, Matthew Turland takes a look at object-oriented programming and what core concepts lie at its heart.
What is object-oriented programming? The acronym OOP has become a bit of a buzzword in the current age of programming, to the point where the waters of its definition have become rather murky. [...] PHP may not be object-oriented, but from a purist perspective, neither is Java. What do I mean by "purist perspective?" Plain and simple: everything is either an object or a message being passed between objects (where message parameters are also objects).
He mentions one of the first languages to support objects (Simula) and the four fundamental concepts that would make a language truly OOP - abstraction, inheritance, encapsulation, polymorphism. Its his opinion, though, that while its good for languages to adhere to these four principles as much as they can, discussions about how well they adhere to them is usually just "spinning your wheels" and don't have much use.
voice your opinion now!
object oriented definition abstraction inheritance encapsulation ploymorphism
PHPBuilder.com: Class Inheritance with PHP
by Chris Cornutt February 18, 2008 @ 07:58:00
On PHPBuilder.com today, there's a new tutorial that takes a beginning look at PHP5's class inheritance model.
There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code. Class inheritance may sound complicated, but think of it this way. Consider a tree. A tree is made up of many parts, such as the roots that reside in the ground, the trunk, bark, branches, leaves, etc. Essentially inheritance is a connection between a child and its parent.
They choose to go with a "car" illustration instead and show how a child of the Product class (Car) can access the private properties of the parent. They also include an example of it in action with a bit of HTML output.
voice your opinion now!
inheritance class php5 object private protected public tutorial
|
Community Events
Don't see your event here? Let us know!
|