Jessica Posted January 31, 2007 Share Posted January 31, 2007 Why can I override certain functions, but not others? Example: (not the real code)[code]<?phpClass myClass{ var $str function extract(){ return $this->str; } function print(){ return $this->str; }}?>[/code]It's fine with extract(), but when I add in the print() one, I get a parse error saying unexpected print. Why can I do this with extract but not print? Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/ Share on other sites More sharing options...
toplay Posted January 31, 2007 Share Posted January 31, 2007 You're mising a semi-colon after var $strExtract() is a reserved function, while print() is reserved too but it's a language construct (can be used without parenthesis).It's usually a bad idea to use variable or function names that are the same or similar to PHP reserved words.hth. Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/#findComment-173269 Share on other sites More sharing options...
Jessica Posted January 31, 2007 Author Share Posted January 31, 2007 As I mentioned it's example code, so there isn't really a ; missing.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/#findComment-173325 Share on other sites More sharing options...
Hypnos Posted January 31, 2007 Share Posted January 31, 2007 I googled around and found this:http://bugs.php.net/bug.php?id=14178&edit=1 Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/#findComment-173445 Share on other sites More sharing options...
toplay Posted January 31, 2007 Share Posted January 31, 2007 Thx Hypnos. As I mentioned, it's a bad idea to use PHP resrved words for pretty much anything. Same goes for MySQL - some people like to use a column name of password but it's reserved (you should use a different name or enclose it in backtick marks `password` within SQL and stored procedures). Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/#findComment-173647 Share on other sites More sharing options...
Jessica Posted January 31, 2007 Author Share Posted January 31, 2007 Yeah every now and then I accidentally use a reserved MySQL word without knowing, and after a few minutes of trying to debug a query that looks fine, I always check the list.I looked up functions, etc in the manual, but it didn't occur to me that print was a reserved PHP word. :D Quote Link to comment https://forums.phpfreaks.com/topic/36415-solved-overriding-functions-in-classes/#findComment-173666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.