On Wed, 2007-07-18 at 09:05 -0600, Richard K Miller wrote: > > The change between 4 and 5 was bigger than deprecating functions. > > PHP 4 > > allowed > > > > $this = classname; > > > > to change the definition of an object on the fly. That doesn't > > work at > > What happens to existing variables and methods when an object is > modified like this? Is this considered a valuable construct for a > language to have?
This seems to be an unintended misfeature. You can read the discussion here: http://www.php.net/manual/en/migration5.oop.php As far as whether this is a valuable feature or a problem: The more dynamic a language is, as a rule, the fewer lines of code you need to write to do a given thing. JavaScript is even more dynamic than PHP, you can add and remove object methods and properties at will. Java and C++ are at the opposite extreme. The trade-off seems to be that more dynamic languages are quicker to write and harder to find subtle bugs in, whereas static languages are slower to write, but the compiler helps you find bugs. For example, I'm now trying to get a certain Perl program to run on my machine. This requires installing all the needed CPAN modules. In a dynamic language, a module might not be loaded until execution requires it. How can I tell whether I really have everything needed? In a dynamic language, I have to execute every possible path through the code. In a strongly typed language the compiler will tell me. The main use of $this = whatever; in PHP 4 seems to be to create a new object within the class definition. This can be accomplished in PHP 5 with a few more lines of code. The PHP 5 version is probably easier to understand and debug. YMMV. It may not be a coincidence that most of the serious software engineering tools written in the last few years have been written in Java. Some of them have been ported to PHP, for example ant => phing and javadoc => phpdoc. I believe this might be because it's easier in some ways to manage a large codebase if it's written in a strongly typed language, and Java is more portable than C++ (although slower and bulkier). -- Walt _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
