-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
With PHP 8.0 (beta4) instantiating a new instance with a FQN (i.e. including the namespace), PHPCS will raise the following unrelated issue:
Parentheses must be used when instantiating a new class
Code sample
<?php
namespace ArthurHoaro;
class PhpCsBugReport
{
public function method(): void
{
$foo = new \DateTime();
$foo = new \Other\Namespance\Unknown();
$foo = new Unknown();
}
}Custom ruleset
N/A
To reproduce
Steps to reproduce the behavior:
- Create a file called
PhpCsBugReport.phpwith the code sample above. - Run
composer require "squizlabs/php_codesniffer" - Using PHP 8.0 run
vendor/bin/phpcs --standard=PSR12 PhpCsBugReport.php. - See error message displayed
FILE: /usr/src/myapp/PhpCsBugReport.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
9 | ERROR | [x] Parentheses must be used when instantiating a new
| | class
10 | ERROR | [x] Parentheses must be used when instantiating a new
| | class
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Expected behavior
Same behavior as with PHP 7.x, no issue should be raised here.
Versions (please complete the following information):
- OS: Ubuntu 20.04
- PHP: 8.0.0-beta4
- PHPCS: 3.5.6
- Standard: PSR12
Additional information
Running PHPCBF will generate a PHP syntax error:
<?php
namespace ArthurHoaro;
class PhpCsBugReport
{
public function method(): void
{
$foo = new() \DateTime();
$foo = new() \Other\Namespance\Unknown();
$foo = new Unknown();
}
}Metadata
Metadata
Assignees
Labels
No labels