Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 shows a warning on routes with dynamic variables #212

Closed
juhana opened this issue Mar 18, 2022 · 3 comments · Fixed by #216
Closed

PHP 8 shows a warning on routes with dynamic variables #212

juhana opened this issue Mar 18, 2022 · 3 comments · Fixed by #216

Comments

@juhana
Copy link

juhana commented Mar 18, 2022

On routes that have dynamic, non-regex variables (e.g. /foo/:id) there's a warning on PHP 8.1 about passing null to substr:

Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in vendor/shardj/zf1-future/library/Zend/Controller/Router/Route.php on line 288

The line is this:

if (substr($part, 0, 2) === '@@') {

It should be:

if ($part !== null && substr($part, 0, 2) === '@@') { 

$part can be null at that point as mentioned on line 96 ("stores [its] regex requirement or null") and there's already another null check later on line 298, so it's not a case of an invalid route or other configuration issue.

@alexkuusk
Copy link

if (substr($part ?? '', 0, 2) === '@@') {
would also work

@alexgit2k
Copy link

Or

$part = $this->_parts[$pos] ?? '';

instead of

$part = $this->_parts[$pos];

@alexgit2k
Copy link

$part = $this->_parts[$pos] ?? ''; does not work, because there is a check for $part !== null afterwards.
Used the solution of juhana which is already used in the same way a few lines below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants