Skip to content

Allow passing false to the $length parameter of substr #7533

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ function str_ends_with(string $haystack, string $needle): bool {}

function chunk_split(string $string, int $length = 76, string $separator = "\r\n"): string {}

function substr(string $string, int $offset, ?int $length = null): string {}
function substr(string $string, int $offset, int|false|null $length = null): string {}

function substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|array {}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 963bd7624ec5f981ac9074eef94f9da740aa5108 */
* Stub hash: 453ac1d55fb43fbb4fbc89942a10fc26e5a94383 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
Expand Down Expand Up @@ -927,7 +927,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_substr, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
ZEND_ARG_TYPE_MASK(0, length, MAY_BE_LONG|MAY_BE_BOOL|MAY_BE_NULL, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY)
Expand Down
9 changes: 9 additions & 0 deletions ext/standard/tests/strings/substr_strict.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Testing substr() with strict types
--FILE--
<?php

declare(strict_types=1);

echo substr('foo', 1, false);
--EXPECT--