Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 2.67 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Hey up guys,

How often does it annoy you when some newbie comes along and decides to use your favorite language and then turn around and say it's crap because it can't do this this and this...?

I had someone send me an email the other day asking me what they thought about an article they were writing on PHP and half of it was wrong. For example, it was quite funny when he said that PHP doesn't take OOP seriously.

When you get a book on PHP or browse many articles online, half the time they tell you the core basics. They don't even mention stuff like reflection, class auto loading, the SPL (Standard PHP Library), etc. The hidden things about PHP that really show its power.

So... here is a quick example using SPL in PHP 5.2 (for best results).

Iterators

When you create an object, would'nt it be nice if you could iterate over the object in a foreach loop? Such as
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <?php
  2. $messages = new messages();
  3. foreach ($messages as $message) {
  4.        print $message;
  5. }
  6. ?>
If you do this
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <?php
  2. class messages extends Iterator {
  3.  
  4. }
  5. ?>
and inside implement the following methods:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <?php
  2. interface Iterator {
  3.        function current();
  4.        function key();
  5.        function next();
  6.        function rewind();
  7.        function valid();
  8. }
  9. ?>
then any object implementing that interface can be used natively in a foreach loop!

Array Overloading

Another example is an array... if you create an object that implements ArrayAccess... allowing you to do code like:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <?php
  2. $messages = new messages();
  3. $messages[] = 'hello';
  4. $messages[] = 'hello again';
  5. $messages[] = 'how are you';
  6. print $messages->get_messages();
  7. ?>
It's this kind of stuff people don't know about before they decide to make bad comments about languages like PHP. And these two examples i gave are the tip of the iceberg using the most basic of interfaces provided by the SPL.

Have you guys ever got annoyed about stuff like this?

Kind regards,
Scott
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
If you made money from keeping your profile up to date, say $30 and up, per month. What extra time would you spend on your profile?

No extra time
A few hours at weekends
A whole day each week
Every minute i can get free


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved