Date: 05/16/00
- Next message: Faisal Nasim: "Re: [phplib-dev] Question about broken OOP stuff"
- Previous message: James McCann: "[phplib-dev] Question about broken OOP stuff"
- In reply to: James McCann: "[phplib-dev] Question about broken OOP stuff"
- Next in thread: Faisal Nasim: "Re: [phplib-dev] Question about broken OOP stuff"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
James McCann wrote:
>
> Hello, I am using PHP at work and have run into several
> difficulties using the OO features of PHP. I ended up
> having to use a number of irritating workarounds that
> will make the code harder to maintain.
>
> Specifically:
> $obj[0]->get_next()->display();
> Doesn't work
PHP is not an OO oriented language. OO features are limited by design.
Someone could even say classes just introduce new namespace no more...
I hope I understand the above, although I don't have a real OO
background. In PHP you must translate it to something like this:
$foo = $obj[0]->get_next();
$foo->display();
... and yes if you had not display() but compute() you would even have
to copy the modified object back to the array $obj:
$foo = $obj[0]->get_next();
$foo->compute();
$obj[0] = $foo;
There're several other points where you can see that the OO features are
limited:
+++ abstrac +++
You can't define abstract methods. Use a workaround insted:
function foo() {
die()
}
+++ static +++
Not available with PHP3, you have to wait for PHP4.
+++ introspection +++
Pretty poor. In PHP3 you have to treat an object like an array and use
gettype() to find out about instance vars and functions.
$f = new foo;
reset($foo);
while (list($k, $v)=each($foo))
echo "$k => $v<br>";
PHP4 gives you some new functions. They are named somewhat like
get_class_vars(), get_instance_vars() etc.
+++ multiple inheritance +++
No multiple inheritance, no interfaces, no inner classes - hmmh.
+++ constructor +++
The parent constructor is not called automatically, you have to call it
manually.
+++ deconstructor +++
Not available.
> Also variable interpolation doesn't seem to work right:
> # OK
> print $obj[0]->string . "<br>\n";
> # OK
> printf("%s<br>\n", $obj[0]->string);
> # Broken
> printf("$obj[0]->string<br>\n");
Only simple expressions are understood as you noticed already.
> Also:
> # Broken
> $obj[0]->iarray[0] = 13;
> $obj[0]->display();
>
> Other than the problems w/ object referencing I find that
> PHP fits the bill for our project quite nicely, & I would
> like to continue to use it, but I don't think it will be
> possible to use it if OO stuff is broken. Do you have any
> idea when these might be addressed?
OO features are not broken just limited. If you have an OO background
you'll feel like in stone age. All the goodies are not available in PHP.
PHP was not made for OO programming and maybe will never be. Some guys
even doubt that OO features are unnecessary for "these little scripts in
the web". I personally don't think so, but this belongs on the php-dev
(maybe php-pear) list not on the phplib-dev list.
Ulf
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Faisal Nasim: "Re: [phplib-dev] Question about broken OOP stuff"
- Previous message: James McCann: "[phplib-dev] Question about broken OOP stuff"
- In reply to: James McCann: "[phplib-dev] Question about broken OOP stuff"
- Next in thread: Faisal Nasim: "Re: [phplib-dev] Question about broken OOP stuff"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

