Skip to content

PHP4 style constructor test#109

Merged
wimg merged 2 commits intoPHPCompatibility:php70from
grubolsch:php70
Jun 23, 2016
Merged

PHP4 style constructor test#109
wimg merged 2 commits intoPHPCompatibility:php70from
grubolsch:php70

Conversation

@grubolsch
Copy link
Copy Markdown

No description provided.

@wimg
Copy link
Copy Markdown
Member

wimg commented Jun 23, 2016

Thank you for your contribution ! Great job !

@wimg wimg merged commit 4ff9ba3 into PHPCompatibility:php70 Jun 23, 2016
@MarkMaldaba
Copy link
Copy Markdown
Contributor

MarkMaldaba commented Jun 23, 2016

This sniff is not quite correct.

PHP4-style constructors are only deprecated if there is no PHP5-style constructor. Therefore the following code is fine in PHP 7 and the sniff should not emit an error:

class foo {

    function __construct() {
        echo 'I am the constructor';
    }

    function foo() {
        echo 'I am NOT the constructor';
    }

}

Reference: http://php.net/manual/en/migration70.deprecated.php

@wimg
Copy link
Copy Markdown
Member

wimg commented Jun 23, 2016

Thanks for mentioning it. We'll get it fixed ;-)

@MarkMaldaba
Copy link
Copy Markdown
Contributor

MarkMaldaba commented Jun 23, 2016

Cool.

When adding the unit tests, as well as the example above, I would add a test to cover those two functions in the opposite order (as the implementation should not care about the order of class methods).

It would also be good to have a test that tests the case-insensitivity of the constructor name, e.g.

class foo {

    function FOO() {
        echo 'I am the constructor';
    }

}

I'm not sure if this would currently trigger a sniff error (as it should) or not.

@jrfnl jrfnl modified the milestone: 7.0 Apr 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants