Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 9, 2022

Returning by reference from a void function

<?php
function &test(): void {}

Such a function is contradictory, and already emits the following E_NOTICE when called: Only variable references should be returned by reference.

New sniff to detect this deprecation.

Includes unit tests.
Includes docs.

Refs:

Related to #1299

…ReferenceFromVoid` sniff

> Returning by reference from a void function ¶
> ```php
> <?php
> function &test(): void {}
> ```
> Such a function is contradictory, and already emits the following `E_NOTICE` when called: `Only variable references should be returned by reference`.

New sniff to detect this deprecation.

Includes unit tests.
Includes docs.

Refs:
* https://wiki.php.net/rfc/deprecations_php_8_1#return_by_reference_with_void_type
* https://www.php.net/manual/en/migration81.deprecated.php#migration81.deprecated.core.void-by-ref
* php/php-src@f0b190c
@jrfnl jrfnl added this to the 10.0.0 milestone Mar 9, 2022
@jrfnl jrfnl requested a review from wimg March 9, 2022 00:21
@jrfnl
Copy link
Member Author

jrfnl commented Mar 9, 2022

@afilina 👆🏻 Another new sniff with docs.

@wimg wimg merged commit e321905 into develop Mar 9, 2022
@wimg wimg deleted the php-8.1/new-removedreturnbyreffromvoid-sniff branch March 9, 2022 12:12
@afilina
Copy link
Contributor

afilina commented Mar 11, 2022

@jrfnl I only saw it today. I recommend to remove the em markup from the code examples in the xml docs. It appears as-is in the markdown files.

@jrfnl
Copy link
Member Author

jrfnl commented Mar 11, 2022

@afilina Thanks for looking these over. Regarding the <em>, they are there intentionally and need to stay in. The standard PHPCS generators support this correctly.

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