RE: [PHP-DEV] RE: PHP 4.0 Bug #6193 Updated: new object makes a shallow copy
| From: | Heinz Doerr | Date: | Fri, 18 Aug 2000 20:32:59 +0000 |
| Subject: | RE: [PHP-DEV] RE: PHP 4.0 Bug #6193 Updated: new object makes a shallow copy | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-29525@lists.php.net to get a copy of this message | ||
Stanislav ,
>>> Sorry, you misunderstand what references are in PHP. The are not like
>>> pointers in C. Not even close.
Sorry - I don't. I designed and partially implemented very large projects.
using reference counted C++ classes (C++ w/o pointers).
I knew very well Java, Perl, ...
A compared PHP4.0 with our referere counted classes - and it's close.
There are just 4 design and implementation bugs.
The PHP was very close to a clean reference counted design.
Better than Java (no garbage collection), better than C++ (no counters
anymore). For me the best compromise for circular references in a reference
counted environment is to leave it to the class designer to unset the class.
PHP fails, because:
- The double &'s are crazy and a very bad compiler design.
This is not a bug - it's just a very bad design.
Implementers give there problem back to the user, that's all.
- just never, never do implicit shallow copies
(C++: copy constructor, Java: special function, ...)
- member(&x) { $x= &$this; } is broken.
$x= &give_me_your_this(); // works
member_function() { $x= &this; }; // fails
- references-to-references does not work:
$x= &$y->member();
$z= $x->member(); // works
$z= $y->member()->member(); // fails
- a automatically called destructor would leave the cleanup to
the class designer. So the class user need to worry.
These 4 points are simple - and very close to the overall PHP design.
But, missing those 4 makes PHP very bad for using classes. Today, the
PHP class behaviour is good for fun, but ...
>>> Please, read some theory on reference counting systems. Every paper on
>>> this topic states clearly that the main and almost unavoidable problem
of
>>> pure reference counting system is isolated circular references.
I DID many times in my live!!!!
Please read yourself again - they discuss compilers handling this case
automatically. Yes this is a bad problem, garbage collections ......
BUT, look at my example (the 100.000.000 loop). I as a class designer
can destruct the circular reference easily. But, it's now the responsibility
of the class designer not of the compiler.
It's like mathematical equations: If you ignore the assumptions, you will
never
anderstand the equations.
OK, my conclusion out of this discussion: we will give up PHP for everything
more than 10 lines.
JSP seems very clear better suited for complex design.
(too bad, I'm not a friend of Sun, I dislike garbage collections,
manuals 10 feet long, but I like the working, not broken object model!).
Please understand, we would have never used PHP3 because of the oo
limitations.
After reading the planned changed it looked great. But those 5 issues from
above
are just too much - plus too many, who should first read books about oo and
reference
counting before impementing a compiler with oo structures. Sorry.
Greetings
Heinz
-----Original Message-----
From: Stanislav Malyshev [mailto:stas@zend.com]
Sent: Freitag, 18. August 2000 21:03
To: Heinz Doerr
Cc: 'Bug Database'
Subject: Re: [PHP-DEV] RE: PHP 4.0 Bug #6193 Updated: new object makes a
shallow copy
HD>> The change:
HD>> 1.) The new constructor always returns references or alternatelly
HD>> we would need a syntax like &new
HD>> 2.) The assignment operator handles references as references not
HD>> as the value of the reference.
>>> Sorry, you misunderstand what references are in PHP. The are not like
>>> pointers in C. Not even close.
--
Stanislav Malyshev stas@zend.com
+972-3-6139665 ext.106