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? 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. 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
Archived
This topic is now archived and is closed to further replies.