Braclayrab Posted January 18, 2007 Share Posted January 18, 2007 Hi, i'm trying to use the pear logger to simply log some data to a file. When I make a test script it works fine:require_once($_SERVER["SITE_HTMLROOT"].'/Include/MyLogger.php');$myLogger->log("foo error", PEAR_LOG_ERR);//This worksContents of MyLogger.php:<?php require_once 'Log.php';//the Pear Logger$myLogger = &Log::singleton("file", $_SERVER["SITE_HTMLROOT"]."/my.log");?>However, when I try to use $myLogger from within a class member-function I get an error:"Call to a member function log() on a non-object in /home/10213/domains/mrmoviepants.com/html/Include/RSA.php on line 345"As you can see, i'm trying to debug the Pear RSA Library but I don't believe that in particular is relevant. Any ideas?Thanks in advance!-ClayUPDATE:I wrote another quick test script:<?phprequire_once("testinclude.php");echo($testvar);Class testfoo{ function test() { //echo($testvar); if(isSet($testvar)) { echo($testvar); } else { echo("cannot find testvar<BR>"); } }}$myFoo = new testfoo();$myFoo->test();?>testinclude.php:<?php$testvar = "this is my testvar<BR>";?>output:"this is my testvarcannot find testvar"Is it not possible to access variables outside of a class from inside a member function? I suppose that does makes sense. I think I'm going to try giving my class and errorhandler... Link to comment https://forums.phpfreaks.com/topic/34815-pear-logger-trouble/ Share on other sites More sharing options...
Braclayrab Posted January 19, 2007 Author Share Posted January 19, 2007 UPDATE:this works:$error_handler = create_function('$obj', 'echo("error: ". $obj->getLastError()->getMessage(). "<BR>");');this does not:$error_handler = create_function('$obj', '$myLogger->log("error: ". $obj->getLastError()->getMessage(). "<BR>",PEAR_LOG_ERR);');I get the same error:"Fatal error: Call to a member function log() on a non-object in /home/10213/domains/mrmoviepants.com/html/Admin/test2.php(41) : runtime-created function on line 1"How can I access myLogger from within a class? help!! Link to comment https://forums.phpfreaks.com/topic/34815-pear-logger-trouble/#findComment-164125 Share on other sites More sharing options...
Braclayrab Posted January 19, 2007 Author Share Posted January 19, 2007 Update(i'm retarded):function logError($obj){ $myLogger = &Log::singleton("file", $_SERVER["SITE_HTMLROOT"]."/my.log"); $myLogger->log("error: ". $obj->getLastError()->getMessage(). "<BR>",PEAR_LOG_ERR);}$rsa_obj = new Crypt_RSA;$rsa_obj->setErrorHandler(logError);this works, obviously. I suppose I could have done this inline as well.I hope this thread helps someone else. >.< Link to comment https://forums.phpfreaks.com/topic/34815-pear-logger-trouble/#findComment-164149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.