Menu

#909 PHPParser does not parse $o->{'c'} syntax

closed-fixed
nobody
None
5
2009-11-10
2007-09-19
Russ Brown
No

I brought this up in 1758184 but that got closed without resolution.

To recap, the following syntax is valid PHP and is used in situations where the property string is something that either PHP itself won't parse properly or when the string is a PHP keyword:

// This doesn't do what you expect:
$o->some-element;

// This is valid PHP, but PHPParser complains about it:
$o->{'some-element'};

I find this syntax very useful when using SimpleXML for example.

Discussion

  • Matthieu Casanova

    Logged In: YES
    user_id=285591
    Originator: NO

    Hi, there is a version here : http://hoyo.free.fr/jedit/PHPParser.jar
    could you try with this one ?

    Matthieu

     
  • Matthieu Casanova

    • status: open --> pending
     
  • Russ Brown

    Russ Brown - 2007-09-19

    Logged In: YES
    user_id=665310
    Originator: YES

    I tried the version you linked to, but got this error:

    [error] ErrorListDialog$ErrorEntry: /usr/share/jedit/jars/PHPParser.jar:
    [error] ErrorListDialog$ErrorEntry: Requires version 0.9.0 or later of gatchan.jedit.hyperlinks.HyperlinksPlugin,
    [error] ErrorListDialog$ErrorEntry: but gatchan.jedit.hyperlinks.HyperlinksPlugin is not installed.

    I can't find that plugin anywhere... :(

    Thanks.

     
  • Russ Brown

    Russ Brown - 2007-09-19
    • status: pending --> open
     
  • Matthieu Casanova

    Logged In: YES
    user_id=285591
    Originator: NO

    Hi, sorry this is a plugin that I didn't release yet. But this dependency is not necessary yet, I forgot to remove it.
    Could you try again ?

     
  • Russ Brown

    Russ Brown - 2007-09-20

    Logged In: YES
    user_id=665310
    Originator: YES

    Hi,

    The plugin loads this time, but doesn't fix the problem.

    I do however have a little more information for you now: the warning is only generated when 'variable may be unassigned' is enabled in the PHPParser options. I guess it's taking the surrounding {}'s to mean it's a variable like {$var}.

    Thanks.

     
  • Matthieu Casanova

    Logged In: YES
    user_id=285591
    Originator: NO

    Hi, could you be more explicit please ?
    Could you give an example of code that cause the error, tell what kind of error and what is the message displayed.

    Matthieu

     
  • Russ Brown

    Russ Brown - 2007-09-20

    Logged In: YES
    user_id=665310
    Originator: YES

    Hi,

    I've written a self-contained example that triggers the problem, and in doing so noticed an odd contition that needs to be true before it happens. Basically, it doesn't happen at all in global scope, only when in a function. The following example was written against 5.2 and shows the problem:

    <?php

    $xml = <<<EOF
    <?xml version="1.0" encoding="UTF-8" ?>
    <file>
    <some-element>Foo</some-element>
    </file>
    EOF;

    $o = simplexml_load_string($xml);

    //
    // The following two lines end up doing the same thing
    //

    // This calls the function below
    output_value($o);

    // This does it directly, using identical syntax to the function version
    // PHPParser doesn't have a problem with this
    echo (string)$o->{'some-element'};

    function output_value(SimpleXmlElement $o)
    {
    // This is identical to the version before in global scope,
    // but PHPParser underlines the "{'some-element'}" part with the
    // following error message:
    // warning, usage of a variable that seems to be unassigned yet: 'some-element'
    echo (string)$o->{'some-element'};
    }
    ?>

    Hope this helps!

     
  • Matthieu Casanova

    I think this is fixed in 1.2.7 that will be released soon

     
  • Matthieu Casanova

    • status: open --> pending-fixed
     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB