Bug 475867 - [PHP7] Introduce static operation validator
Summary: [PHP7] Introduce static operation validator
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Dawid Pakula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 465701
  Show dependency tree
 
Reported: 2015-08-26 03:56 EDT by Dawid Pakula CLA
Modified: 2020-05-14 13:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dawid Pakula CLA 2015-08-26 03:56:30 EDT
Since version 7, php no longer validate static operations on parser level.

After merge patch from bug 466967 we lost errors for cases like this:

class Foo {
  const MY_CONST = callMe();
}

We should reintroduce it via additional checker in ParserBuildParticipant.
Comment 1 Dawid Pakula CLA 2018-02-28 08:48:50 EST
I'm thinking about this issue because sometimes driving me crazy  :P
Comment 2 Eclipse Genie CLA 2018-03-01 11:46:29 EST
New Gerrit change created: https://git.eclipse.org/r/118442
Comment 4 Michele Locati CLA 2018-03-05 04:49:40 EST
I think that this change could have broken something.

I have a PHP 5.5 project with this code:

<?php

class ClassName
{
    protected $propertyName = array(
        'test' => 'Foo\Bar',
    );
}

Now PDT marks this property with this error:
"Constant expression contains invalid operations"

BTW this syntax is valid since PHP 5.0: see https://3v4l.org/5sJL7
Comment 5 Michele Locati CLA 2018-03-05 05:36:42 EST
The same "Constant expression contains invalid operations" error is reported for this valid code too:

<?php
function foo($bar = [])
{
}
Comment 6 Eclipse Genie CLA 2018-03-07 02:58:45 EST
New Gerrit change created: https://git.eclipse.org/r/118864
Comment 7 Eclipse Genie CLA 2018-03-08 10:46:00 EST
New Gerrit change created: https://git.eclipse.org/r/119013
Comment 9 Thierry BLIND CLA 2018-03-12 06:07:22 EDT
Hi Dawid,
there are still false positives!

Following code is totally valid (tested with PHP 5.4):

<?php
class AppConfig
{

    public static $connections = array(
        'prod' => array(
            'user1',
            'password1',
            'db1'
        ),
        'test' => array(
            'user2',
            'password2',
            'db2'
        )
    );
}
?>

Thierry.
Comment 10 Thierry BLIND CLA 2018-03-12 06:40:48 EDT
Another simpler example that should work, but doesn't validate anymore;

<?php
class Main
{
    private $_dbConnections = array();
    private $_emailFileInfos = array();
}
Comment 11 Eclipse Genie CLA 2018-03-12 07:47:37 EDT
New Gerrit change created: https://git.eclipse.org/r/119223
Comment 13 Dawid Pakula CLA 2018-03-13 07:21:54 EDT
Anything else?
Comment 14 Thierry BLIND CLA 2018-03-14 07:44:25 EDT
It seems ok again ;)
I close this bug report and reopen it if necessary.

Thank you for the work, Dawid.