Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » class constant parser bug
class constant parser bug [message #1711541] Fri, 16 October 2015 20:27 Go to next message
Chris Nasr is currently offline Chris NasrFriend
Messages: 3
Registered: October 2015
Junior Member
There is a bug in PDT that incorrectly marks legitimate code as broken.

When accessing a class constant that is an array via self or static it thinks '[' shouldn't be there.

For example.

01: class DataPoint {
02:   const _TO_REGEX		= array(
03:     'int'		=> '/^[+-]?\d+$/',
04:   );
05: 
06:   public function _construct($type, $value) {
07:     if($type == 'int') {
08:       if(!preg_match(self::_TO_REGEX['int'], $value)) {
09:         // throw error
10:       }
11:     }
12:   }
13: }


Gives me the error: "syntax error, unexpected '['" at line 8 and it underlines the '[' in red.

The problem is this code is 100% valid and runs fine. What's even worse if that if I replace "self::" with "$this->" the error goes away, but now the code is truly broken as you can't access a constant using $this.

It's as if someone got their parsing backwards when it comes to constants. Or perhaps the lack of dollar sign in the statement is what is tripping up the parser. Either way, this is a bug and needs to be fixed.
Re: class constant parser bug [message #1711561 is a reply to message #1711541] Sat, 17 October 2015 10:29 Go to previous messageGo to next message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 207
Registered: March 2013
Senior Member
This bug has been fixed in PDT 3.6 : https://bugs.eclipse.org/bugs/show_bug.cgi?id=459420


PDT 3.6 is part of Eclipse Mars.1


Re: class constant parser bug [message #1711739 is a reply to message #1711561] Mon, 19 October 2015 13:26 Go to previous messageGo to next message
Chris Nasr is currently offline Chris NasrFriend
Messages: 3
Registered: October 2015
Junior Member
Oh, excellent, I will try that out. Thanks so much Dawid
Re: class constant parser bug [message #1711759 is a reply to message #1711739] Mon, 19 October 2015 14:15 Go to previous messageGo to next message
Chris Nasr is currently offline Chris NasrFriend
Messages: 3
Registered: October 2015
Junior Member
No Message Body

[Updated on: Mon, 19 October 2015 14:24]

Report message to a moderator

Re: class constant parser bug [message #1711761 is a reply to message #1711759] Mon, 19 October 2015 14:17 Go to previous message
Dawid Pakula is currently offline Dawid PakulaFriend
Messages: 207
Registered: March 2013
Senior Member
Constant array access is available since PHP 5.6 so make sure you have project (or wide workspace) set to PHP 5.6 or 7

Previous Topic:Eclipse MARS can run any .php but not index.php!
Next Topic:Content Assist for self variables not working
Goto Forum:
  


Current Time: Wed Jan 24 03:53:14 GMT 2018

Powered by FUDForum. Page generated in 0.01848 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software