casper_ghost Posted January 5, 2012 Share Posted January 5, 2012 Hi all while in the process of learning php, I wrote some code and couldn't work out why it wouldn't work, After going through everything with a fine tooth comb I couldn't see the problem. Then out of luck I removed $this I had assigned as a variable and it worked. replacing it back into the code broke it again. Is this a bug or does it mean something in php? Quote Link to comment https://forums.phpfreaks.com/topic/254437-bug-or-syntax-error/ Share on other sites More sharing options...
Philip Posted January 5, 2012 Share Posted January 5, 2012 $this is reserved. See the manual for more info: The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object). Quote Link to comment https://forums.phpfreaks.com/topic/254437-bug-or-syntax-error/#findComment-1304624 Share on other sites More sharing options...
Pikachu2000 Posted January 5, 2012 Share Posted January 5, 2012 Additionally, you should be developing with the following directives set in your php.ini file (then restart Apache): error_reporting = -1 display_errors = On If you had error_reporting set appropriately, you would have gotten this error: Fatal error: Cannot re-assign $this in /Applications/MAMP/test.php . . . Quote Link to comment https://forums.phpfreaks.com/topic/254437-bug-or-syntax-error/#findComment-1304625 Share on other sites More sharing options...
casper_ghost Posted January 5, 2012 Author Share Posted January 5, 2012 thank you for your replies, I know it should be turned on, I turned it off some time ago to force myself to look for bugs when the code breaks... but it will be a good idea to turn it on next time i can't find the error. cheers guys. Quote Link to comment https://forums.phpfreaks.com/topic/254437-bug-or-syntax-error/#findComment-1304629 Share on other sites More sharing options...
trq Posted January 5, 2012 Share Posted January 5, 2012 You should always develop with error reporting and display error on. Quote Link to comment https://forums.phpfreaks.com/topic/254437-bug-or-syntax-error/#findComment-1304631 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.