We help IT Professionals succeed at work.

Classes and variables

ncw
ncw asked
on
231 Views
Last Modified: 2006-11-17
I'm wanting to create a php debugger using the code at http://www.zend.com/zend/tut/tutorial-DebugLib.php#_How_it_Works

I could use a function library, but I've chosen to try a class. There are 3 files:
testclass.php
application_top.php
debug.php

If I open testclass.php then I get the error: "Notice: Undefined property: debug_msg in e:\inetpub\wwwroot\TestClass\testclass.php on line 5"
The code in each file is as follows:
**********************************************************************************
testclass.php:
<?php
  require('application_top.php');
  $debug.debug_msg['Hello'];
 ?>

application_top.php:
<?php
  require('debug.php');
  $debug = new debug();
?>

debug.php:
<?php
  class debug {
      // class methods
      function debug_open_window()
      {
            static $window_opened = FALSE;
            if(!$window_opened)
            {
                  ?>
                  <script language="JavaScript">
                  debugWindow = window.open("","debugWin","toolbar=no,scrollbars,width=600,height=400");
                  debugWindow.document.writeln('<html>');
                  debugWindow.document.writeln('<head>');
                  debugWindow.document.writeln('<title>PHP Remote Debug Window</title>');
                  debugWindow.document.writeln('</head>');
                  debugWindow.document.writeln('<body><font face="verdana,arial">');
                  debugWindow.document.writeln('<hr size=1 width="100%">');
                  </script>
                  <?
                  $window_opened = TRUE;
            }
      }

      function debug_msg($mesg)
      {
            $this->debug_open_window();
            print "<script language='JavaScript'>\n";
            print "debugWindow.document.writeln('".trim(nl2br($mesg))."<br>');\n";
            if (debug_on == 'true'){
                  print "debugWindow.document.writeln('On<br>');\n";
            }
            else {
                  print "debugWindow.document.writeln('Off<br>');\n";
            }
            print "self.focus();\n";
            print "</script>\n";
      }
  }
?>

**********************************************************************************

Can anyone advise please? Do I need to declare the function debug_msg as public? I tried it and there was no difference.

Comment
Watch Question

Commented:
I see a C or C++ Programmer :)
> <?php
>   require('application_top.php');
>   $debug.debug_msg['Hello'];
>  ?>

This will work
<?php
  require('application_top.php');
  $debug->debug_msg['Hello'];
?>
---
WysG - "Codito Ergo Sum"
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
ncw

Author

Commented:
I had changed -> to . and back to -> just before you posted and it at least opens the debug window now, but there is a problem with writing to the debug window. I get an IE error message:

Line: 12
Char: 1
Error: syntax error
Code: 0
Url: http://192.168.0.1/textclass.php

and the source of the debug window is:

<html>
<head>
<title>PHP Remote Debug Window</title>
</head>
<body><font face="verdana,arial">
<hr size=1 width="100%">

Is it the reference to debugWindow in function debug_msg?
ncw

Author

Commented:
function debug_msg in debug.php now looks like this:

     function debug_msg($mesg)
     {
          $this->debug_open_window();
          print "<script language='JavaScript'>\n";
          print "debugWindow.document.writeln('".trim(nl2br($mesg))."<br>');\n";
          print "self.focus();\n";
          print "</script>\n";
     }
  }

It's the print command which is causing an error.
ncw

Author

Commented:
No, it seems to be the reference to the 'debugWindow'. It worked as two functions outside this class (as per url).
ncw

Author

Commented:
I've combined the two functions and the following class code works:

<?php

  class debug {

      var $debug_on=false;
      var $window_opened=false;

      // class constructor
      function debug($ip) {

            $this->debug_on = 'true';
            //if (($ip == '192.168.0.2')||($ip == '80.168.47.224')) {$this->debug_on='true';} else {$this->debug_on='false';}
      }

      // class methods

      function debug_msg($mesg)
      {
        if ($this->debug_on == 'true'){
            if($this->window_opened==false){
            ?>
            <script language="JavaScript">
            debugWindow = window.open("","debugWin","toolbar=no,scrollbars,width=600,height=400");
            debugWindow.document.writeln('<html>');
            debugWindow.document.writeln('<head>');
            debugWindow.document.writeln('<title>PHP Remote Debug Window</title>');
            debugWindow.document.writeln('</head>');
            debugWindow.document.writeln('<body><font face="verdana,arial">');
            debugWindow.document.writeln('<hr size=1 width="100%">');
            </script>
            <?
            $this->window_opened = true;
            }
            print "<script language='JavaScript'>\n";
            print "debugWindow.document.writeln('".trim(nl2br($mesg))."<br>');\n";
            print "self.focus();\n";
            print "</script>\n";
        }
      }
  }
?>

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.