RE: [PHP4BETA] A quick clarification question about PHP4...

From: Date: Tue, 24 Aug 1999 15:39:45 +0000
Subject: RE: [PHP4BETA] A quick clarification question about PHP4...
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-3687@lists.php.net to get a copy of this message
> -----Original Message----- > From: Zeev Suraski [mailto:zeev@zend.com] > Sent: 24 August 1999 05:04 PM > To: Samuel Liddicott; Jim Brain; Andi Gutmans; Zend > Subject: RE: [PHP4BETA] A quick clarification question about PHP4... > > > At 16:54 24/08/99 , Samuel Liddicott wrote: > > >is clear to humans but we are now forced to arrange it differently. The > >annoying thing is that this is the kind of thing machines are > good at! The > >parser should recognize the type of things it is can't > initialize statically > >(or how will it report an error) and then initialize by code it > in a secret > >hidden pre-construtor. > > Uhh no, you're not forced to arrange it differently at all - $this->foo = > $bar is an expression, just like $foo = $bar. It's not static > initialization, it's not member variable initialization, it's nothing. I know. The re-arrangement is from: class thingy { var $field=GetRandomName(); } to: class thingy { var $field; function thingy() { $field=GetRandomName(); } } And whatever C++ does or doesn't do, writing: class thingy { var $field=GetRandomName(); } is amazingly shorter and clearer. The same for: function x($a=$b[0],$c=$d[0]) { which must now be written as: function x($a) { if (!isset($a)) {$a=$b[0];} [Although I think you sed that this was a parser problem with no workaround] > >The closer we get to C++ the further we get from scripting, I fear. > > It really has little to do with C++. It has to do with a compile&execute > model, vs. an interpreter model. The compile&execute model is > much, much > better. In that case why stick to the C++ model of static initializers? When you compile: var $field=GetRandomName(); stick it in a hidden pre-constructor or a post-memory-allocator or something so it gets compiled, and then executed in the right place. Developer gets clear flexible code, php compiles it and then executes it. The code should parse ok, and the compiler will have to build up a hidden function bit by bit and then finish compiling it when the class definition is complete. Or just eval the string before you call the constructor but I imagine you'd want to compile it. Sam

« previous php.version4 (#3687) next »