Page 1 of 2
Is PHP5 fully OO?
Posted: Mon May 23, 2005 10:33 am
by chrisgoff
Hi
I am trying to answer a question that is likely to come up in one of my final year exams in the next few days...is PHP5 fully object oriented, or merely object based?
I don't know an awful lot about object oriented programming if I'm honest, so what I've cobbled together is a somewhat limited understanding on which I'm basing any evaluation of this answer, so any help in pointing out mistakes will be much appreciated!
I have identified the main principles of an OO language of it being able to support; classes and instances of those classes (objects), encapsulation, inheritance, extensibility and polymorphism.
From what I've read on a variety of sites, including the PHP manual, I seem to have determined that PHP5 handles all the above. My lecturer however, seems to have the opinion that another necessity of an OO language is that it supports data hiding, and that PHP5 does not. I however, disagree, as I have read various bits and pieces about defining the visibility of classes and methods in PHP5 using the public, protected and private key words. Have I got this right?
Anyway, if anyone can shed an opinion on this question I'd much appreciate it.
Cheers
Posted: Mon May 23, 2005 10:49 am
by malcolmboston
from what i understand PHP5 is a quite competent OOP language, but still, there are much better OOP languages (Java for eg)
many of the functionalities you require will be found in PHP5 however, bare in mind, PHP was not designed as an OOP language but rather, it was brought into the mainstream with PHP5, PHP has always had the ability for OOP design but it was somewhat limited
Ive never coded in php5 and to be honest, i have no need to for the foreseeable future, but i should imagine that PHP5 will be able to do 99% of the things you require although some stuff will probably be buggy as it is very much in its "first stage" of OOP based "language"
mcGruff etc will be able to answer you much better as i know they love OOP and can help you out
Posted: Mon May 23, 2005 10:52 am
by chrisgoff
Cheers malcolm...
Look forward to hearing from any other significantly-better-phpers-than-myselfs out there

)
Chris
Posted: Mon May 23, 2005 1:06 pm
by Pyrite
Afaik, PHP5 supports data hiding by declaring class data members private instead of public. So your teacher is wrong (afaik)
I believe the concept data hiding is refered to as Visibility in PHP5.
Posted: Mon May 23, 2005 2:22 pm
by McGruff
In php4 the ability to freelly access notionally private class properties can be convenient when you're unit-testing. For example, say you have an error message passed to a trigger_error call. In a test, you can set up the error state and then:
Code: Select all
$this->assertError($foo_class->_bar_error_message);
If the error text is edited, it doesn't require a corresponding edit to the test (it would if you'd asserted a specific string). Changing the interface by adding a getter just for the test would change the apparent intent of the class ever so slightly.
Posted: Mon May 23, 2005 3:01 pm
by andre_c
I would consider PHP5 fully object oriented, but i found this on the manual:
In PHP 5, object comparison is more complicated than in PHP 4 and more in accordance to what one will expect from an Object Oriented Language (not that PHP 5 is such a language).
which makes me think that the makers of php don't think so
... or maybe they just don't want to argue about it

Posted: Tue May 24, 2005 5:26 am
by timvw
this question can be easily answered once you answer the following question:
- What do you expect from a language that claims itself to be OOP? What are the requirements?
- Lookup if you can achieve them easily with PHP.
Posted: Fri May 27, 2005 6:51 pm
by malcolmboston
McGruff wrote:In php4 the ability to freelly access notionally private class properties can be convenient when you're unit-testing. For example, say you have an error message passed to a trigger_error call. In a test, you can set up the error state and then:
Code: Select all
$this->assertError($foo_class->_bar_error_message);
If the error text is edited, it doesn't require a corresponding edit to the test (it would if you'd asserted a specific string). Changing the interface by adding a getter just for the test would change the apparent intent of the class ever so slightly.
lmao, like i said "mcgruff will know as i know he likes OOP", i didnt bloody understand a word of what you just said mate

Posted: Fri May 27, 2005 7:56 pm
by Ambush Commander
OOP in PHP is not mandatory, like in some languages. Kinda obvious, but doesn't that mean that PHP is not fully object oriented?
Posted: Sun May 29, 2005 5:39 pm
by Pyrite
Therefore, php object-oriented programming can just be called 'poop'

Posted: Sun May 29, 2005 10:02 pm
by andre_c
Ambush Commander wrote:OOP in PHP is not mandatory, like in some languages. Kinda obvious, but doesn't that mean that PHP is not fully object oriented?
hmm, would C++ be considered fully object-oriented then?
Posted: Sun May 29, 2005 10:11 pm
by Ambush Commander
Not really:
http://en.wikipedia.org/wiki/C_Plus_Plus
Wikipedia wrote:It is a statically typed free-form multi-paradigm language supporting procedural programming, data abstraction, object-oriented programming, and generic programming.
Most languages these days, I venture, are not purely one thing: they expanded into other areas, sometimes with weird results. Perl, for example, can handle multi-leveled arrays, but it's an incredibly complex mix of references that took me several days to figure out (I definitely would not like to work with those in Perl).
Closer to home, remember when PHP just started off? It was "Personal Home Page" tools, a collection of "small tight cgi binaries written in C". But it turned out that people wanted to "use the framework for creating add-ons... ... being able to embed logic directly in their web pages for creating conditional HTML, custom tags, and other features." And then, they created the if tag. And then the else tag. And then the whole kaboodle (Shamelessly ripped off from the Introduction in Programming PHP by Rasmus Lerdorf and Kevin Tatroe).
It's kinda pointless then to argue whether or not a language is "fully" a paradigm, rather, you should ask whether or not it fulfills all the requirements of the paradigm and fulfills them well (like many previous posters mentioned).
Posted: Sun Jun 05, 2005 7:52 am
by MathewByrne
Having programmed in Java for the past few years I'm well aware of the capabilities of an Object Oriented language. PHP5 is a
very capable OOP language. That said it doesn't have the power or versatility of Java but is a huge step forward from PHP4.
Your lecturer is wrong, PHP5 does support private and protected functions and variables. (
See here for more info) and really does a lot more to promote encapsulation than previous versions.
Posted: Mon Jul 25, 2005 7:38 am
by fastfingertips
PHP5 is not a full OOL.
Is just enough to see how method overloading works and this will take you out of your minds

.
Posted: Wed Jul 27, 2005 5:37 pm
by andre_c
fastfingertips wrote:PHP5 is not a full OOL.
Is just enough to see how method overloading works and this will take you out of your minds

.
err... you can't overload methods in php (i'm guessing you meant overriding)