[PHP] problems using chr() in an Object
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); If I eliminate all the lines that initializa text variables with chr() everything works OK, else I get these errors. Any idea on whey this is happening? -- 09:01:41 up 26 days, 17:30, 3 users, load average: 1.18, 0.80, 0.54 - Martín Marqués| select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems using chr() in an Object
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: class T { var $a = 'a'; var $b = 2; var $c = array('whatisthis' = 'er?'); var $d = false; } what you want to do should be done in the constructor (aka ctor) class T { var $textInicio; /* ctor - * if you're using php5 you should call this function __construct() */ function T() { $this-textInicio = chr(27) . chr(64); // etc } } If I eliminate all the lines that initializa text variables with chr() everything works OK, else I get these errors. Any idea on whey this is happening? yes! hopefully you do to now :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems using chr() in an Object
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++)? -- 09:42:14 up 26 days, 18:11, 3 users, load average: 0.40, 0.49, 0.60 - Martín Marqués| select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems using chr() in an Object
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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php