 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Lorna Mitchell: A Little More OOP in PHP
by Chris Cornutt November 01, 2012 @ 09:23:54
Lorna Mitchell has republished a previous article about OOP (following this entry) introducing you to some of the core object-oriented programming concepts in PHP.
This time around we'll look at some more advanced concepts and some more practical examples of building code, covering use of constructors and how to add access modifiers in to control how calling code can operate on your objects. We'll also show off how to create static methods and properties and, perhaps more importantly, illustrate applications of these features.
She talks about initializing objects with constructors, working with "statics" and using instanceof to determine the object type. Sample code is included to help illustrate the concepts.
voice your opinion now!
oop objectoriented programming introduction tutorial
Lorna Mitchell: Introduction to PHP OOP
by Chris Cornutt October 15, 2012 @ 11:56:06
Making the transition from the procedural PHP world into the object-oriented world of some more complex applications can be difficult. It requires a shift in thinking that might take some learning. Lorna Mitchell has posted an introduction to some of the common concepts.
Since the introduction of PHP 5 in 2004, PHP has had an object model worthy of that description and became a truly modern language for use on the web. [...] Using OOP (Object Orientated Programming) enables us to architect our systems much more clearly, and to make them more manageable and more maintainable. This technique also allows us to separate form from function to create clean, navigable codebases with plenty of opportunities to reuse code, apply design patterns and bring in concepts from other brances of computer science.
She covers some of the more common pieces you'll need to know to start venturing into OOP in PHP including: objects versus classes, using properties/methods, inheritance and access modifiers. Some sample code is included that works with user records in a database (along with the SQL to create the tables).
voice your opinion now!
introduction objectoriented programming class object
Chris Morrell's Blog: Introducing Zit, an object-oriented dependency injection container
by Chris Cornutt March 23, 2012 @ 12:57:43
In his latest post Chris Morrell introduces a project he's been working on to help with his dependency injection needs - Zit, an object-oriented dependency injection container similar to the Pimple DIC from Fabien Potencier.
I'll admit right now that I'm fairly new to the world of dependency injection containers. I usually do my dependency injection "manually" and have always thought that there must be a better way. Then I came across Pimple, which is a wonderfully simple solution to the problem. The only thing about it is that I hate its array-oriented interface. Something about $container['session_storage'] rubs me the wrong way.
The Zit tool should be very familiar to any user of Pimple, as it implements similar functionality, just in an OOP kind of way. He includes some example code in the post showing how to create a database connection object and inject it into the Zit container. You can find the latest code for the tool over on github.
voice your opinion now!
dependency injection container zit objectoriented
Freek Lijten's Blog: Book Review - Growing Object-oriented software guided by tests
by Chris Cornutt March 12, 2012 @ 13:57:57
Freek Lijten has a new post to his blog - a review of a book (from Freeman & Price) called "Growing Object-Oriented Software Guided by Tests". It's based on Java, but the ideas presented can be applied pretty universally.
It may seem strange but I'd like to start out with giving my opinion on this book: It is brilliant! If you don't like reading my post you at least know what you should do next: buy the friggin' book. The book offers some theory concerning agile development, (unit-)testing and code quality but its killer feature is the almost 200 page long example of developing an application the TDD way! In the rest of this post I will shortly highlight different parts of the books and stuff I enjoyed or learned from it.
He breaks up the review in to a few different parts - the process of test-driven development, his "first real lesson", their working example and a section about the more advanced topic of sustainable test driven development.
voice your opinion now!
objectoriented tdd testdrivendevelopment software book review
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
RubySource.com: Confessions of a Converted PHP Developer Animal Abuse
by Chris Cornutt June 27, 2011 @ 13:40:02
In another entry in his "Confessions of a Converted PHP Developer" series Mal Curtis about a typical class development path PHP developers take and how it can be a limiting, linear progression from one step to another.
In converting to Ruby I realized how strict PHP is in its class hierarchy. This surprised me as I'd always viewed PHP as a very loose language, mainly due to its loose typing and lack of formal code structure guidelines. [...] I find most PHP developers learn starting by using inline PHP as a low learning curve entry point into dynamic web languages and then move on to fuller, more complex, applications.
He includes a few code samples comparing how Ruby, while still allowing the same kind of structure, also lets you redefine classes on the fly. His example shows redefining a method in a Ruby class using a method commonly called "monkey patching". It's good that he points out a downfall of the approach too:
I must note that Monkey Patching is often a quick fix solution that can create headaches for future developers (or for yourself, if your memory is like mine) for several reasons. [...] Use at your own risk!
There's several different articles all over the web talking about the "monkey patching" approach and if it's possible/useful in PHP.
voice your opinion now!
monkeypatching ruby compare class objectoriented rubysource
Slawek Lukasiewicz's Blog: Working with date and time in object oriented way
by Chris Cornutt June 10, 2011 @ 08:13:14
Slawek Lukasiewicz has a new post today about working with dates and times in PHP on a more object-oriented fashion than in the more traditionally procedural way of just calling PHP date/time functions on the string values.
Date and time manipulation in PHP is mostly connected with functions like: date, time or strtotime. They can be sufficient, but if we want to deal with dates like with objects - we can use DateTime class. DateTime class is not only straightforward wrapper for standard functions, it has a lot of additional features - for example timezones.
He shows how to use the DateTime functionality to return an object you can call several different methods on. He gives examples of the formatting call, comparing one DateTime object to another, how to update the date after the object's created, calculating the difference between two dates and iterating through a certain time period.
voice your opinion now!
time date datetime objectoriented procedural tutorial
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
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
Web Builder Zone: The PHP paradigms poll results OOP wins
by Chris Cornutt October 05, 2010 @ 11:21:17
According to this new post on the Web Builder Zone, the results of a poll taken about the best programming method for PHP these days is - by far - object-oriented programming.
After two weeks of gathering votes, the PHP paradigms poll is now closed. With 216 votes (73%), the winner paradigm in popularity is Object-Oriented Programming. The old procedural approach to PHP, which has given fame to Wordpress and Drupal, is coming to an end. Even Drupal 7 has an object-oriented database layer as a primary component, and this paradigm is by far the most diffused in the world for web sites and applications written in high level languages (different from C).
While the overwhelming amount of votes went to OOP, there were still a few for some of the other options including the second place winner - procedural programming. He also talks a bit about OOP's current place in the PHP ecosystem and how it has allowed for certain great tools to be developed, but how it also has a good ways to go in functionality.
voice your opinion now!
poll paradigm results oop objectoriented procedural
|
Community Events
Don't see your event here? Let us know!
|