NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[resolved] Cannot access self::


Joined: 25 Jul 2006
Posts: 70
Reply with quote
Lately I've been seeing some strange errors when debugging. These errors only happen when I'm using the debugger such as from a DebugBreak().

Getting errors:
- Using $this when not in object context
- Cannot access self:: when no class scope is active

Neither of these conditions should be true, the code works fine when not using a debugger, produces no errors.

This is also stable code, hasn't changed in a long time, these errors just started showing up when I tried to debug something.

Any idea what's up?

I've installed 5.2.5 and the latest version of the debugger, I'm on Windows using Apache 2.2.x
View user's profileFind all posts by cpriestSend private message


Joined: 25 Jul 2006
Posts: 70
Reply with quote
The thought just occurred to me that I'm using APC now, does the debugger not work with APC?

What if I turn off the caching of scripts but leave APC installed for the apc_store/fetch()?
View user's profileFind all posts by cpriestSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
What PhpED version/build number do you use? and could you please submit a screenshot illustrating the problem?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 25 Jul 2006
Posts: 70
Reply with quote
I've attached a screen shot. With the screen shot, the function mysql_escape() is being called from line 401 (also shown) using $this->mysql_escape() so $this is valid.

I have also tested the APC deal by not loading it via extension= line, same problem.

Running
Code:
PhpED 5.2 (Build 5229)

PHP 5.2.5 (cli) (built: Nov  8 2007 23:18:51)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
    with DBG v3.2.12, (C) 2000,2007, by Dmitri Dmitrienko
    with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies


View user's profileFind all posts by cpriestSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
$this is a very senstive keyword in php. Try to remove all statements with $this from Watches.
What's about screenshot with self:: ?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 25 Jul 2006
Posts: 70
Reply with quote
I didn't have that code in there as an example, but calling self:: any function would fail with the error I posted originally.

Clearing out all of my watches and breakpoints has cleared up the issue, thanks!

Incidentally, I did have $this as a watch variable but it would only cause that error when it went to execute a line with $this or self:: in it.
View user's profileFind all posts by cpriestSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I noticed earlier that sometimes watches may cause such problems. It was fixed but seems not completely. I'd highly appreciate if you post a sample that will replicate the error with $this or self:: or better both.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
Hey Dmitri,

I just experienced the same problem with the "self::" thing (no class scope) with DBG 3.2.12. Reading this post (and having a lot of watches) I tried to remove them one by one and test every time until I found the one that caused the problem.

Consequently, I spent about 4 hours scaling down my framework to find out what exactly causes the problem and I'm glad to tell you that I did it Smile
You need to fullfill a number of prerequisites to trigger the error:
- You need an __autoload function and it HAS to be in an included file, not in the file that is initially called.
- You need to have a watch that points to a static variable in a non-existing class (it needs the :: scope). I used "Error::$gnError" for my tests.
- You need to break in the static class function that will execute the "self::" call.
- The autoload function has to require/require_once() a file and fail (include() doesn't work) .

Given all that, reproducing the problem is fairly simple:
test.php:
Code:
<?php
   include ( 'test2.inc.php' );
   Test::Test1 ( );
?>

test2.inc.php:
Code:
<?php

function __autoload ( $sClass )
{
   require ( 'thisisanonexistingfile.php' );
}

class Test
{
   static function Test1 ( ) { self::Test2 ( ); } * breakpoint here
   static function Test2 ( ) { }
}

?>


Make sure the breakpoint is set where indicated (DebugBreak works as well, as long as it's IN the function).
Simply run test.php.
I assume the reason it crashes is pretty simple. The __autoload function is called because of the watch and it causes a require statement to fail. Normally when a require fails it terminates PHP.
Because it is the debugger causing this failure, attempting to show information in the watch window (and thus wouldn't fail under normal circumstances) execution continues, but internally PHP probably did some cleanup stuff already etc... causing the scope error later on.

Hope that helps!

Edit:
I'm using PHP 5.2.4 on a 3rd party Apache/2.0.59 (Win32) server with DBG v3.2.12. For your viewing pleasure I have made my phpinfo() available here
View user's profileFind all posts by BlizzSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Thanks for report.
Problem is fixed in dbg 3.2.14/phped 5.2.5234

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
You're welcome, glad I could help.
(You guys are fast Very Happy)
View user's profileFind all posts by BlizzSend private messageVisit poster's website
[resolved] Cannot access self::
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic