Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fatal error: Class declarations may not be nested" when debugging with Netbeans #67

Closed
JohnArcher opened this issue Sep 24, 2015 · 3 comments

Comments

@JohnArcher
Copy link

Hi there,

first I want to apologize if this not the right place to post this ... :-( I am using KLogger and PSR Log (https://github.com/php-fig/log) together with Symfony's ClassLoader Component (https://github.com/symfony/class-loader) to autoload KLogger and PSR Log.

My test code looks like this:

<?php

require_once __DIR__.'/class-loader/ClassLoader.php';

use Symfony\Component\ClassLoader\ClassLoader;

$loader = new ClassLoader();
$loader->register();

$loader->addPrefix('Psr\\Log', __DIR__);
$loader->addPrefix('Katzgrau\\KLogger', __DIR__);

$users = array(
    array(
        'name' => 'Kenny Katzgrau',
        'username' => 'katzgrau',
    ),
    array(
        'name' => 'Dan Horrigan',
        'username' => 'dhrrgn',
    )
);

$logger = new Katzgrau\KLogger\Logger(__DIR__.'/logs');
$logger->info('Returned a million search results');
$logger->error('Oh dear.');
$logger->debug('Got these users from the Database.', $users);

Everything works fine under this conditions:

  1. I do not debug
  2. I do debug (Netbeans, XDebug) and step into new Katzgrau\KLogger\Logger()

It does not work, if I set a breakpoint before new Katzgrau\KLogger\Logger() and when the breakpoint is reached I click "Continue (F5)". Then I get this fatal error:
Fatal error: Class declarations may not be nested in path\to\project\Psr\Log\LogLevel.php on line 9

I tried a lot to figure out what is going on. The only workaround I found was uncomment use Psr\Log\LogLevel; in Logger.php and copy the class definition of Psr\Log\Level directly into Logger.php (that's why I am posting it here).
But for obvious reasons I don't want to modify your code this way.

Does anyone know what and why is this happening?

Thanks a lot!

Regards

@katzgrau
Copy link
Owner

Yeah, not really a KLogger problem. At least the problem seems limited to debugging and setting a breakpoint at a specific place. It could be a potential issue with xdebug. I would check php's error_log to see if there's anything more specific in there.

@JohnArcher
Copy link
Author

Thanks for your answer. Nope, error_log has no more infos.

@onno-vos-dev
Copy link
Contributor

I have never seen this issue before and done plenty of debug sessions.

Can you tell us your exact setup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants