peej/phpdoctor

Fatal error: Call to undefined method RootDoc::packageName() in phpDoctor.php on line 877

MichaelClerx opened this issue · 8 comments

For some reason having more than one class constant in a class causes this error for me.

Fatal error: Call to undefined method RootDoc::packageName() in (...)/classes/phpDoctor.php on line 877

The bug only appears when the class is in a namespace

peej commented

Hi Michael,

I can't recreate this issue, can you either create a test case to expose it or send through a snippet of the code you run in on that causes the problem.

Thanks,
Paul.

This is all it takes:

<?php

namespace ag\form

{

    class Test

    {

        const A = 1;

        const B = 2;


    }

}

The .ini file is pretty much the default one

peej commented

I don't know much about PHP5.3 namespaces, but I think the issue may be to do with the syntax you've used. If I use:

namespace ag\form;

Then it works fine, but your curly braces syntax then PHP stops without giving me an error or finishing.

I'm presuming that the curly braces syntax has been deprecated, but it's hard to find out anywhere. Any ideas? Can you give the other syntax a try and see if you still get the error.

BTW: I've only tested it with PHP5.3.3. What version are you using?

No it's a legit way of doing things, even the recommended way if you include multiple namespaces in a single file: http://www.php.net/manual/en/language.namespaces.definitionmultiple.php

We're using 5.3.3 too, I'll check if the alternate syntax runs without errors when I get home.

By the way, thanks for taking this up so quickly!

I can now confirm that it works fine with the alternative syntax.

As an aside, should error_reporting really be set to 0 ? It took me quite a while to realize you'd done this during which I scanned every log I could. As it stands, errors cause the script to die silently.
Why not settle for E_ALL & ~E_DEPRECATED ?

Here's a fix:

case T_NAMESPACE:
case T_NS_C:
    $namespace = '';
    while($tokens[++$key][0] != T_STRING);
    $namespace = $tokens[$key++][1];
    while($tokens[$key][0] == T_NS_SEPARATOR)
        $namespace .= $tokens[$key++][1] . $tokens[$key++][1];
    $currentPackage = $defaultPackage = $oldDefaultPackage = $namespace;
    $key--;
    break;

I'm not sure about the $key-- at the end, the convention is to leave the key pointing at the last handled token?

peej commented

Thanks for the fix Michael, I've implemented it and added tests.