|
Posted by Jochem Maas on 04/28/05 16:00
Martín Marqués wrote:
> El Jue 28 Abr 2005 09:42, Jochem Maas escribió:
>
>>Martín Marqués wrote:
>>
>>>I have an object class in which I'm doing chr() calls, especifically in
>
> the
>
>>>definition of some variables, and when loading the class I get this error:
>>>
>>>Parse error: parse error, unexpected '(', expecting ',' or ';' in
>
> Ticket.inc
>
>>>on line 51
>>>
>>>Line 51 has:
>>>
>>> var $textoInicio = chr(27) . chr(64);
>>
>>you can only assign 'basic' values (types) to vars in the class definition
>>(so no function calls) . e.g:
>
>
> Yes, that's how I solved it just a minute ago, even though I didn't understand
> why. Thanks for the enlightenment. :-)
>
> BTW does PHP5 let you assign function values in the variable definition (like
> C++)?
no. I believe the reasoning is that allowing you to define class vars with return
vals from functions opens the door to endless possibilities of weird side effects when
you load in the class. e.g:
class T
{
var $reconfigured = sometimesCompletelyReconfigureTheWebserver();
var $filesystemdeleted = recursiveDel('/');
}
you can imagine what kind of havoc the 2 imaginary functions may cause just by loading
the class T - I believe that the php devs want to avoid nightmares/confusion (especially for
'average' php coders) by not allowing this kind of syntax/[var-]definition. besides which there
are probably scope issues - imagine you want to pass a var to sometimesCompletelyReconfigureTheWebserver()
.... what is the scope of the var, where does it come from?
>
[Back to original message]
|