Is PHP5 fully OO?
Moderator: General Moderators
Is PHP5 fully OO?
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
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
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
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
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
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:
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.
Code: Select all
$this->assertError($foo_class->_bar_error_message);
Last edited by McGruff on Sat Aug 06, 2005 1:34 pm, edited 1 time in total.
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
I would consider PHP5 fully object oriented, but i found this on the manual:
... or maybe they just don't want to argue about it
which makes me think that the makers of php don't think soIn 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).
... or maybe they just don't want to argue about it
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
lmao, like i said "mcgruff will know as i know he likes OOP", i didnt bloody understand a word of what you just said mateMcGruff 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:
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.Code: Select all
$this->assertError($foo_class->_bar_error_message);
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Not really: http://en.wikipedia.org/wiki/C_Plus_Plus
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).
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).Wikipedia wrote:It is a statically typed free-form multi-paradigm language supporting procedural programming, data abstraction, object-oriented programming, and generic programming.
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).
- MathewByrne
- Forum Commoner
- Posts: 38
- Joined: Sat Mar 27, 2004 9:49 pm
- Location: Australia
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.
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.
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact: