PHP 5 OO In 24 Slides 56
An anonymous reader writes "At php|works about a week ago John Coggeshall gave an interesting talk on object oriented programming using PHP version 5. Even if you couldn't be at the talk, his slides are available online which gives you a pretty good idea of what you can expect from the OO model. Java programmers will be pleased."
Re:PHP isn't bad (Score:3, Interesting)
It really depends on what you are trying to achieve but I used PHP CLI many times to solve quick problems. PHP's impressive function library makes it easy to do anything. Can you give me an example where PHP isn't suitable for general scripting?
BTW, I agree PHP is better at web than scripting. Now back to the main topic...
As always, Coggle (I just need to spread John's 'short' name) used his PHP girls in the slides.
These are far from being the first slides about PHP 5 available. I had seen some fr
Error on slide 5 (Score:2, Informative)
Member methods may also be declared final, preventing them specifically from being overloaded in a sub class
s/overloaded/overridden/
See here [planetmirror.com].
Re:Error on slide 5 (Score:1)
That URL says override but it's just a point of view, the real name is method overloading. AFAIK.
google "php method overloading [google.com]" returns 35,000 links.
google "php method overriding [google.com]" returns 16,000 links
Re:Error on slide 5 (Score:3, Informative)
PHP 5 introduces the "final" [php.net] keyword to declare final members and methods. Methods and members declared final cannot be overridden by sub-classes.
overload [php.net] has a specific meaning.
Re:Error on slide 5 (Score:2)
Re:Jave programmers pleased? (Score:1, Funny)
Oh great. A Lisp zealot and an OO zealot all in one person. Such will probably trigger a singularity and end civalization. Much more toxic than even the mod points I am surely about to receive.
Re:"Java programmers will be pleased" (Score:2)
Re:"Java programmers will be pleased" (Score:2)
1)Its too big. With 1500 classes there's no way a developer can keep a significant chunk in his mind
2)Its too big part 2- the bigger the library, the more bugs it has
3)Having one giant library that does 10 billion things isn't a good idea. Its better to have individual libraries written, and have more focus on those libraries by the teams. Huge projects like Java's framework end up producing subpar code
4)It kills innovation. In languages without large standard libraries, implementati
Re:"Java programmers will be pleased" (Score:1, Insightful)
In what way is a standard library of 1500 classes, all documented in the same place, harder for developers to understand than 200 different libraries each implementing 10-15 classes?
2)Its too big part 2- the bigger the library, the more bugs it has
Of course 1500 classes are likely to contain more bugs than 15 classes. But do you have any evidence that those classes are likely to be buggier as a result
Re:"Java programmers will be pleased" (Score:2)
Because the developer doeesn't have to learn 200 libraries, he'd only need to learn the subset he frequently uses. The java class library is very highly coupled. To use the networking part, you need to understand all the data structures part.
Of course 1500 classes are likely to contain more bugs than 15 classes. But do you
Re:"Java programmers will be pleased" (Score:2)
Re:"Java programmers will be pleased" (Score:2)
Point by point (Score:2)
So you're saying that if a networking library requires a linked list or hashtable it should roll its own rather than reusing an existing, efficient implementa
Re:"Java programmers will be pleased" (Score:1)
You also make the point that it is good to be able to pick and choose which library to use, slating Java because it does not allow this. Since when did Java not allow you to use whatever library you want? If you want to write your own HashMap, LinkedList or implementation of the networking libraries, or use someone else's, go right ahead. Whet
Re:"Java programmers will be pleased" (Score:2)
A) Sun implemented too much functionality. (1, 2)
B) All of that functionality is built into one library instead of separate downloadable libraries. (3)
C) Every JVM is required to come with the library. (4, 5)
I respectfully but wholeheartedly disagree with you on all points.
A/1,2) I applaud Sun for raising the bar in delivering so much functionality. For the most part, the packages are well organized enough that the classes you don't use don
history of PHP OO? (Score:2)
As many times as I've heard this fun fact, it never ceases to amaze me: "In ZE / PHP 4 objects weren't references, so when they were passed to a function a copy was made."
I've never heard this one before, and it's just as ridiculous: "In PHP 4, you couldn't access a member function or properity indirectly through another object's member function or properity.."
Yikes. How did they get it that wrong!?
Re:history of PHP OO? (Score:2)
If anything, the fact that PHP4's OO features worked as well as they did was impressive. The fact that they were limited was due to the point at which they were implemented. If anything, it illustrates the need to plan features early in the development cycle.
--
Evan
Re:history of PHP OO? (Score:1)
Those who know enough to use it know that when it comes to web development with a bent towards obect-orientation there are far more pleasant (syntactically and/or semantically) alternatives.
Those who don't know the benefits of such an approach will see the huge library of built-in functions and think that must be the way to do things.
They would have been better off delaying the final releas
Re:history of PHP OO? (Score:1)
"They would have been better off delaying the final release of PHP5 a year or two and just going through and converting the entire library to an OO model. That would be a step in the right direction."
i think that would have made it Java or C#, both of which are really nice languages, but a scripting language shouldn't _have_ to be OO, just have the ability to do it if you want. i like the way it stands now, OO if you want it, or just straight-forward procedural scripting if you want it like th
Re:history of PHP OO? (Score:1)
I'm thinking of things like:
$arr = array();
array_push($arr, 42);
vs.
$arr = new array();
$arr->push(42);
To me that removes a lot of redundancy, plus, making core functionality reusable via standard OO mechanisms would be a significant improvement.
Of course, proper namespaces/packages would help as well. The previous example might look more like:
$arr = array::new();
array::push($arr, 42);
Though there's still redundancy here, in that I know $arr is an array, and I
Re:history of PHP OO? (Score:1)
i understand where you are coming from in your example, but still disagree that that's the way it should have been done. allow me to expand on your example.
$arr = array();
array_push($arr, 42);
can also be done like this as long as _everything_ isn't an object.
$arr[] = 42;
which couldn't be done if it was all switched to OO, which is why i prefer having OO avaialable instead of necessary. now i ca
Re:history of PHP OO? (Score:2)
There's nothing really non-OO about this, as long as the syntactic sugar of [] can be translated into a method/attribute call.
Re:history of PHP OO? (Score:1)
Againb, with Ruby on the brain, the simpler syntactic sugar would be:
$arr << 42;
Re:history of PHP OO? (Score:4, Informative)
PHP 3 was a procedural language and designed as such. Rasmus made it that way, and when you look at the code for php.net, or other code Rasmus made or approved, you'll see that he has a case and a reason for all this.
PHP 3 had so called classes and objects, which were just a fancy syntax for hashes of values and functions, added as a midnight hack by Zeev and Andi to the language. Also, that hack was severely buggy. I ought to know, because I tried to use it in implementing PHPLIB at that time, and filed over 60 bug reports against PHP 3 during the six release candidates for it.
PHP 4 tried to extend PHP 3's object capabilities, but that extension was driven mostly by Zeev, who admittedly had little knowledge of or interest in OO. Also, he tried to model PHP 4's OO capabilities with the image of C++ in mind. During the PHP 4 lifecycle, I tried several times to nudge Zeev and the PHP community into the direction of Smalltalk and Objective-C, which provide an object model that is much better suited to a scripting language than C++'s model, and also is much more expressive, but my efforts were late and since I decided not to code to the Zend engine itself, somewhat fruitless.
Zend, especially Zeev, did do his homework for the version 5 release, though, and redesigned all things OO from ground up. He did so in front of a backdrop of PHP being used more and more in off-web usecases, that is, PHP 4 slowly becoming a mainstream language leaving its little specialized corner of web applications. Zeev's idea was to provide the version 5 release of the capabilities that are needed for PHP to become a real scripting language that can be used in larger projects, without breaking to much backward compatibility, and with keeping the dynamic "scripting" capabilities and feel of the language.
He succeeded superbly - PHP 5 provides the OO you need, and enables you to operate more within the mindset of a Smalltalk or Objective-C programmer than within the mindset of a Simular or C++ programmer. In PHP 5, objects are dynamically typed (class is a property of the object, not a property of the variable name), completely self-descriptive, and capable of delegation, emulation and posing.
Try it out and do not let the syntax deceive you - this is not a C++ or Java like language, try Smalltalk and ObjC for size.
Re:history of PHP OO? (Score:2)
Except for the interfaces and final features, PHP 5 OO looks a lot like that of Ruby (or Python, but more Ruby). Am I right? And I don't know what you mean by "delegation, emulation, posing". (Although I'm guessing _get, _set, and _call have to do with at least one of them.)
I don't have a problem with non-OO languages; I'm not an OO purist. But I do think if you're going to add support for a programming paradigm to your language, you should not design it in such a way that it
Re:history of PHP OO? (Score:2)
And I don't know what you mean by "delegation, emulation, posing". (Although I'm guessing _get, _set, and _call have to do with at least one of them.)
Delegation is a mechanism in the Objective-C Toolkit AppKit as it was sold with NeXTstep. It allows you to set a delegate object for any object. Method calls that cannot be handled by an object with a delegate have a chance to be handled by the delegate instead of the original object before a runtime error i
Re:history of PHP OO? (Score:2)
That is exactly what I always suspected was the case with PHP, but I've never been able to get a serious PHP programmer to confirm it. Thanks.
A little off the subject, but, I don't think Python is an academic kind of language at all; if anything I feel like it's a le
Desperately seeking spellchecker (Score:2, Insightful)
Pleased? Why? (Score:2)
Personally, I'm less than impressed. Why should I cheer and hooray about PHP introducing some OO features in PHP in 2004 almost all of which Java has had since version 1.0 in 1995? Is that supposed to be a great feat?!
Re:Pleased? Why? (Score:2)
Personally, I'm not impressed for other reasons. OO is severely overrated- its a good solution for some problems, its a bad one for others. It is not the holy grail, and its not meant for use on every project. I don't see it as being truely useful for a web scripting language.
Does OOP make sense for web scripting? (Score:1)
OOP clearly makes sense in many applications where the class definitions and objects have a lifetime longer than a single call. And it's possible to write server-side applications that "live" longer than a single HTTP request. But that isn't the PHP execution model.
The ZEND Ac
Re:Does OOP make sense for web scripting? (Score:1, Insightful)
Does it make sense to define classes, create objects, restore objects from some serialized storage or database, etc. etc. in the context of a web application? That's a lot of scaffolding to build and tear down for every HTTP request.
Yes, it does make sense. OO is a way to abstract your code and make it easier to test and re-use.
What do you mean "scaffolding"? Do you have some numbers? Benchmarks? Before/after comparisons? Creating an object is (supposed to be) a lightweight event. You probably use fun
Re:Does OOP make sense for web scripting? (Score:1)
I don't have any problem understanding OOP, thank you -- I've been programming for a long time and learned OOP in Smalltalk and C++ back when they were new.
I'm not asking whether OOP is a worthwhile technique or not. I'm asking if it makes sense, in general, for web applications, where class definitions and object instantiations and initializ
Re:Does OOP make sense for web scripting? (Score:1)
"I'm asking if it makes sense, in general, for web applications, where class definitions and object instantiations and initializations are done to handle a single HTTP request."
yes or no depending on how you look at it
lots of times it doesn't boil down to a single HTTP request. there are lots of web applications that span multiple pages (HTTP requests) and use the $_SESSION for persistence.
i don't think that PHP 5 is really emphasizing OO as much as making sure it's apparent to everyone.
Re:Does OOP make sense for web scripting? (Score:1)
Thanks for answering your own questions.
I did not question OOP in PHP only for performance reasons. And I know that the web applications can maintain state on the server, including PHP applications.
If it is, then I would say that performance is the foremost non-issue of modern software development, and following Moore's law, it becomes 50% less relevant to your development approach every 18 months.
Moore's Law (a conjecture that has more or less held so far) refers to hardware; in fact it refers to th
Re:Does OOP make sense for web scripting? (Score:2)
It is, and overdone OO framework is what makes PHP web applications slow. The faster PHP applications only use a limited amount of OO, and like you did, as a namespace management tool.
But PHP 5 is a base for more than mere web applications. The version 5 update readies PHP to leave the web application scope and makes it a fully blown scripting language. PHP is already being used in this context, albeit not yet fully recognized - mo
Re:Does OOP make sense for web scripting? (Score:1)
But PHP 5 is a base for more than mere web applications. The version 5 update readies PHP to leave the web application scope and makes it a fully blown scripting language. PHP is already being used in this context, albeit not yet fully recognized - most people still associate PHP with the web, like you did.
I know that PHP 5 is being positioned as more than a web language. I doubt it will succeed there. That space is well-served by more mature and better thought-out dynamic languages such as Perl and Pyth
Re:Does OOP make sense for web scripting? (Score:2)
For many people, earlier versions of PHP have been their first programming language. Wait to see them grow up - PHP grows with them.
Re:Does OOP make sense for web scripting? (Score:1)
For many people, earlier versions of PHP have been their first programming language.
I don't know which crowd of young programmers I'm more worried about -- those who learned PHP as their first language, or those who learned Java. I've mopped up enough amateur PHP (and ASP/VBScript) projects in the last few years. It's a flashback to the days when people learned some simple home computer BASIC and then got a job in corporate IT. Not necessarily bad, but you sure can learn a lot of bad habits, and fail to
Re:Does OOP make sense for web scripting? (Score:1)
Let me add an example of what I'm getting at. Is this:
Somehow worse or less preferable than this:
Re:Does OOP make sense for web scripting? (Score:1)
Java and C# are both object oriented languages and have hugely successful related web development platforms (J2EE and
static typing (Score:2)
I'll be pleased when PHP gets static typing.
Re:static typing (Score:1)
I'll be pleased when PHP gets static typing.
Why? If you want that just use Java.
Adding more and more Java-like features to PHP is going down the wrong path. Web programmers took to PHP enthusiastically because the language is simple, the libraries are extensive (if not always robust), and you can get something working fairly fast.
If PHP continues to bloat with OOP and exceptions and perhaps static typing, it will lose its advantage and appeal. If PHP morphs into a kind of patchwork Java -- with all o
"You're not Ali. You're not even...literate." (Score:2, Informative)
Java Devs will be Pleased (Score:1)