dhinge Posted November 1, 2009 Share Posted November 1, 2009 I have an object called "logger" inside of $this, which I'm trying to use inside of a function (not a method). function parseDate($date) { $this->logger->debug($this, "date is $date"); // parse parse parse } I run it and get "Fatal error: Using $this when not in object context". If I add: "global $this" I get: Fatal error</b>: Cannot re-assign $this I have to have "$this" to run the logger, so how do I get the function to recognize $this? Quote Link to comment https://forums.phpfreaks.com/topic/179849-using-this-inside-a-function/ Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 The reserved $this variable can only be used inside methods of objects. Quote Link to comment https://forums.phpfreaks.com/topic/179849-using-this-inside-a-function/#findComment-948784 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.