I can certainly see a use for strings as Value Objects, if only for 
readability.  Chaining a series of methods is much more readable (to me at 
least) than wrapping a series of functions.  See:

$str = $str->substr(0, 5)->upper()->trim('\n');

vs.

$str = trim(strtoupper(substr(0, 5, $str)), '\n');

That said, the advantage of functions is that you can trivially add your own.  
Adding new methods to a class in PHP requires either inheritance (which is 
very limiting in many ways) or all sorts of thoroughly weird mechanisms for 
sorta implementing mix-ins.  I see that as a more limiting factor than using 
functions instead of methods.

(Not to say that value objects, auto-boxing, prototype inheritance, and other 
semi-functional features aren't cool; I'd love to have more of those in PHP, 
but they're a considerably harder problem to solve.)

I would also dispute the idea that "everything is a class/object" is a 
necessary design feature of a "mature OO language".  It's a design feature of 
Java, which is sort of the poster child of classic OO.  But Javascript takes 
an entirely different, functional-esque approach of everything is an object, 
including classes.  (Weird but cool.)  Python, Perl, and Ruby do their own 
weird things.  C++ has multiple inheritance.  I'm sure there's other 
languages I should mention that I am missing, but you get the idea.  

Don't make things an object unless there's a reason to.  Most of the 
OOP "features" that PHP lacks that would be useful to have are, IMO, the more 
functional-esque stuff from Javascript and its ilk, not classes-all-around.

On Monday 03 December 2007, Jordan Wambaugh wrote:
> Thanks. I was not aware of SPL's file and array classes. As for the string
> class, some of it is done, and should work in 5.x HEAD. I fully plan to add
> Unicode support for PHP 6's HEAD. Is there any other concerns you may have
> about a string class (other than it being a big task)? I think it would be
> great to unify, and standardize all the string functions in PHP into a
> class.
>
> I don't want to rewrite anything already written, so I'll go ahead and take
> a look at ArrayObject and ArrayIterator. I'd love to help PHP as much as
> possible.
>
> Thanks,
> Jordan.
>
>
> -----Original Message-----
> From: Marcus Boerger [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 03, 2007 12:18 PM
> To: Jordan Wambaugh
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] Object Oriented standard Library
>
> Hello Jordan,
>
>    have a look at the SPL extension (Standard PHP Library) which introduces
> a few things (for instance SplFile). Have a look here:
> http://php.net/~helly I do not think we need a string class right now
> unless you want to provide a full unicode one that later works with HEAD
> seamingly. If you are intersted, then the ArrayObject/ArrayIterator
> implementation in SPL can be made much faster. I know what to do but have
> no time for that...
> and as always, help is always welcome here
> and if you have something to show, then show us :-)
>
> marcus
>
> Monday, December 3, 2007, 5:43:19 PM, you wrote:
> > I am currently working on a Object-Oriented Library extension that wraps
> > a lot of functionality in PHP's standard library  dealing with strings,
> > arrays, fileIO, etc. into classes.
> >
> > (String class, Collection class, etc.)
> >
> > This would allow end-users to create objects that represent data types
> > and resources, and take advantage of all the benefits of OOP (object
> > chaining, polymorphism, etc) all in a c compiled extension.
> >
> > Example:
> >
> > $myString=new String("Hello world!");
> >
> > $myLowerCaseString =
> > $myString->copy()->replace("world","universe")->lowerCase();
> >
> >
> >
> >
> >
> >
> >
> > The goal of this project is to help PHP mature into a more
> > object-oriented language with an object oriented library, while
> > addressing a common complaint about the standard library not being very
> > consistent
> > (http://en.wikipedia.org/wiki/Php#Criticism [8th bullet])
> >
> >
> >
> > I have already implemented a couple classes, but would like to get
>
> feedback
>
> > from the PHP development community on the idea of creating such a library
> > for PHP. Also, any suggestions would be greatly appreciated.
> >
> >
> >
> > Thanks,
> >
> >
> >
> > Jordan Wambaugh
>
> Best regards,
>  Marcus


-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to