Skip to content

Commit 397990f

Browse files
committed
Constants/ConstantString: safeguard and document handling of various new php syntaxes
1 parent 5641bca commit 397990f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

WordPressVIPMinimum/Tests/Constants/ConstantStringUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ if ( ! \defined( WPCOM_VIP, ) ) { // Error.
5454
if ( ! DEFINED( WPCOM_VIP ) ) { // Error.
5555
Define( WPCOM_VIP, true ); // Error.
5656
}
57+
58+
// Safeguard correct handling of function calls using PHP 8.0+ named parameters.
59+
\defined( constant_nam: WPCOM_VIP ); // Okay, well not really, typo in param name, but that's not the concern of the sniff.
60+
define(value: true, constant_name: 'WPCOM_VIP', ); // Okay.
61+
define(case_insensitive: true, constant_name: WPCOM_VIP ); // Error.
62+
63+
// Looks like a function call, but is a PHP 8.0+ class instantiation via an attribute.
64+
#[Define('name', 'value')]
65+
function foo() {}
66+
67+
define(...$params); // PHP 5.6 argument unpacking will be ignored.
68+
add_action('my_action', define(...)); // PHP 8.1 first class callable will be ignored.

WordPressVIPMinimum/Tests/Constants/ConstantStringUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function getErrorList() {
2929
50 => 1,
3030
54 => 1,
3131
55 => 1,
32+
61 => 1,
3233
];
3334
}
3435

0 commit comments

Comments
 (0)