Commit graph

49 commits

Author SHA1 Message Date
DanielEScherzer
5dd0575698
Generated arginfo header files: combine preprocessor conditional blocks (#15736)
When functions' or class methods' availability is based on some preprocessor
condition, the generated arginfo header files wrap the declarations in the
preprocessor `#if` conditional blocks, one per declaration, even if they are in
the same conditional block based on comments in the stub file. Instead of
having multiple conditional blocks one after the other with the same condition,
combine them into a single conditional block.
2024-09-04 13:04:22 +02:00
Niels Dossche
f81370847c
Fix GH-13815: mb_trim() inaccurate $characters default value (#13820)
Because the default characters are defined in the stub file, and the
stub file is UTF-8 (typically), the characters are encoded in the string
as UTF-8. When using a different character encoding, there is a mismatch
between what mb_trim expects and the UTF-8 encoded string it gets.

One way of solving this is by making the characters argument nullable,
which would mean that it always uses the internal code path that has the
unicode codepoints that are defaulted actually stored as codepoint
numbers instead of in a string.

Co-authored-by: @ranvis
2024-04-24 09:07:55 +02:00
tekimen
4d51bfa270
[RFC] Add mb_ucfirst and mb_lcfirst functions (#13161) 2024-03-20 17:25:19 +01:00
Máté Kocsis
10957e498c
Do not generate frameless info items when func info generation is disabled
While here, I fixed newlines around arginfo and function entry generation. Previously, newlines were repeated.
2024-02-18 11:39:00 +01:00
Alex Dowad
26b4130f4a Merge branch 'PHP-8.3'
* PHP-8.3:
  Return value of mb_get_info can be NULL
2023-11-27 21:20:38 +02:00
Alex Dowad
31d43164e8 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Return value of mb_get_info can be NULL
2023-11-27 21:13:21 +02:00
Alex Dowad
d8ef868b92 Return value of mb_get_info can be NULL
This has been the case at least since PHP 5.4. Thanks to Girgias for
pointing it out.

It appears that there are several global variables internal to mbstring
which can be queried via mb_get_info() and which could be NULL, but
at the very least, we know that "mbstring.http_input" is one of them.
2023-11-27 20:53:37 +02:00
Yuya Hamada
a80b6d7b99 Add mb_trim function
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2023-11-24 08:04:51 +02:00
Niels Dossche
68591632b2
[RFC] Implement mb_str_pad() (#11284)
Closes GH-10203.
2023-06-20 21:22:04 +02:00
Alex Dowad
97e29bed9e Use shared, immutable array for return value of mb_list_encodings
This will allow us to easily check in other mbstring functions if the
list of all supported encodings, returned by mb_list_encodings, is
passed in as input to another function.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-05-16 07:01:07 -07:00
Máté Kocsis
b4ec3e9bc0
Do not generate CONST_CS when registering constants (#9439) 2022-08-28 08:27:19 +02:00
Ilija Tovilo
a6f489b452
Fix mb_strimwidth RC info
Closes GH-9254
2022-08-05 17:06:23 +02:00
Máté Kocsis
e328c68305
Rename @cname to @cvalue in stubs (#9043)
@cname currently refers to the constant name in C. However, it is not always a (constant) name, but sometimes a function invocation, so naming it as @cvalue would be more appropriate.
2022-07-19 15:11:42 +02:00
Máté Kocsis
56137cd26e
Declare ext/mbstring constants in stubs (#8798) 2022-06-23 17:34:08 +02:00
Máté Kocsis
8e6e9838b0
Add support for generating MAY_BE_ARRAY_OF_REF func info flag (#7416) 2021-08-30 13:50:34 +02:00
Máté Kocsis
fdc6082902
Generate optimizer func info from stubs for various extensions (#7409)
ext/hash, ext/iconv, ext/mbstring, ext/xml, ext/zlib
2021-08-26 19:52:11 +02:00
Máté Kocsis
cad66533f0
Generate class entries from stubs for ldap, libxml, mbstring and mysqli
Closes GH-6684
2021-02-16 14:46:19 +01:00
Nikita Popov
5582490bf2 Normalize mb_ereg() return value
mb_ereg()/mb_eregi() currently have an inconsistent return value
based on whether the $matches parameter is passed or not:

> Returns the byte length of the matched string if a match for
> pattern was found in string, or FALSE if no matches were found
> or an error occurred.
>
> If the optional parameter regs was not passed or the length of
> the matched string is 0, this function returns 1.

Coupling this behavior to the $matches parameter doesn't make sense
-- we know the match length either way, there is no technical
reason to distinguish them. However, returning the match length
is not particularly useful either, especially due to the need to
convert 0-length into 1-length to satisfy "truthy" checks. We
could always return 1, which would kind of match the behavior of
preg_match() -- however, preg_match() actually returns the number
of matches, which is 0 or 1 for preg_match(), while false signals
an error. However, mb_ereg() returns false both for no match and
for an error. This would result in an odd 1|false return value.

The patch canonicalizes mb_ereg() to always return a boolean,
where true indicates a match and false indicates no match or error.
This also matches the behavior of the mb_ereg_match() and
mb_ereg_search() functions.

This fixes the default value integrity violation in PHP 8.

Closes GH-6331.
2020-10-13 20:40:55 +02:00
Nikita Popov
cafceea742 Update mbstring parameter names
Closes GH-6207.
2020-09-28 09:51:58 +02:00
Larry Garfield
94854e0dff Standardize mbstring and string on using 'string' as a parameter name.
Closes GH-6171.
2020-09-21 12:06:50 +02:00
Máté Kocsis
c37a1cd650
Promote a few remaining errors in ext/standard
Closes GH-6110
2020-09-15 14:26:16 +02:00
Máté Kocsis
1c81a34563
Make mb_send_mail() consistent with mail()
The $additional_headers parameter shouldn't accept null.
2020-09-14 11:52:33 +02:00
Máté Kocsis
3e800e997b
Move custom type checks to ZPP
Closes GH-6034
2020-09-02 11:11:38 +02:00
Máté Kocsis
0d330e1a02
Add a few missing parameter types in stubs
Related to GH-5627
2020-07-30 14:26:45 +02:00
Máté Kocsis
ac0da090ae
Fix UNKNOWN default values in ext/mbstring and ext/gd
Closes GH-5598
2020-07-28 17:06:25 +02:00
Nikita Popov
33ddc3bb96 Fix mb_ereg_search* arg and func info 2020-07-21 10:40:08 +02:00
Nikita Popov
c9b9f525a9 Include stub hash in generated arginfo files
The hash is used to check whether the arginfo file needs to be
regenerated. PHP-Parser will only be downloaded if this is actually
necessary.

This ensures that release artifacts will never try to regenerate
stubs and thus fetch PHP-Parser, as long as you do not modify any
files.

Closes GH-5739.
2020-06-24 09:55:19 +02:00
George Peter Banyard
68164f40ce Fix [-Wundef] warning in MBString extension 2020-05-16 15:31:20 +02:00
George Peter Banyard
7dd332f110 Refactor mb_substitute_character()
Using the new Fast ZPP API for string|int|null

This also fixes Bug #79448 which was too disruptive to fix in PHP 7.x
2020-05-11 17:30:01 +02:00
George Peter Banyard
12ec7a2730 Convert if blocks to assertions and adapt stubs accordingly 2020-04-09 13:50:37 +02:00
Máté Kocsis
3709e74b5e
Store default parameter values of internal functions in arg info
Closes GH-5353. From now on, PHP will have reflection information
about default values of parameters of internal functions.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-04-08 18:37:51 +02:00
Nikita Popov
38d93262a0 Update mb_strrpos() stub
We no longer accept the encoding as 3rd param, so we can make this
a proper int argument.
2020-04-08 12:03:14 +02:00
Máté Kocsis
21cfa03f17
Generate function entries for another batch of extensions
Closes GH-5352
2020-04-05 21:15:30 +02:00
George Peter Banyard
1b6f61e7c4 Promote invalid case mode to ValueError in mb_case_converter
Add assertions to check the return value is not NULL as this indicates a bug.
Add identical assertion to mb_strtoupper and mb_strtolower.
This means these functions can't return false anymore, ammend stubs accordingly.
2020-04-05 03:33:08 +02:00
George Peter Banyard
a34e73de5a mb_scrub() can't return false anymore
Also drop the intermediary function which was only used here
2020-04-05 01:44:39 +02:00
George Peter Banyard
656046873c Refactor mb_substr_count()
Promote empty needle warning to ValueError
Convert if branch into an assertion as if mbfl_substr_count fails this now implies a bug
Thus mb_substr_count() can only return int now, fix stubs accordingly
2020-04-02 22:40:00 +02:00
George Peter Banyard
165fde9a37 Convert if branch to assertion in mb_strlen
This operation should never fail, therefore it's converted to an assertion.
Thus this mb_strlen() can now only return int, fix stubs accordingly
2020-04-02 22:40:00 +02:00
George Peter Banyard
d44ee9112f Promote mb_str_split warning to ValueError
Also add a TODO about documenting this funcion on PHP.net
Convert some checks to assertions as if they don't hold something went wrong during memory allocation
Due to these changes this function cannot return false anymore, fix stubs accordingly
2020-04-02 22:40:00 +02:00
Nikita Popov
8a2ce27bba mb_detect_order(): Use proper array|string argument 2020-03-30 16:26:28 +02:00
Nikita Popov
b02b3539e7 mb_check_encoding(): Make var a proper array|string arg 2020-03-30 16:15:12 +02:00
Nikita Popov
50d07ff28c mb_detect_encoding(): Use proper array|string parameter
Needed to add support for nullabiltiy in some places.
2020-03-30 16:15:12 +02:00
Nikita Popov
bb6523693c mb_convert_variables(): Make $from an array|string argument 2020-03-30 15:51:04 +02:00
Nikita Popov
0d24422749 mb_convert_encoding(): Make $input a proper array|string arg 2020-03-30 15:41:55 +02:00
Nikita Popov
f24f6cbab9 mb_convert_encoding(): Make $from_encodings a proper array|string arg
Switching to FastZPP, as we don't support this in normal zpp.
2020-03-30 15:39:33 +02:00
Christoph M. Becker
7d0102dfa7 Revert "Replace @param annotations with type declarations"
This reverts commit c31029f335.
2020-02-17 08:55:18 +01:00
Christoph M. Becker
c31029f335 Replace @param annotations with type declarations 2020-02-16 23:43:38 +01:00
Máté Kocsis
27e83d0fb8
Add union return types for function stubs 2019-11-11 14:54:55 +01:00
Christoph M. Becker
e2100619ac Expect appropriate parameter type in the first place
`mb_encode_numericentity()` and `mb_decode_numericentity()` accepted
arbitrary zvals as `$convmap`, but ignored anything else than arrays.
This appears to be an unresolved relict of their ZPP conversion for
PHP 5.3[1].  We now expect an array in the first place.

We also expect `count($convmap)` to be a multiple of four (else we
throw a `ValueError`), and do no longer special case empty `$convmap`.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=1c77f594294aee9d60e7309279c616c01c39ba9d>
2019-10-07 16:48:08 +02:00
Christoph M. Becker
0a47096c08 Add MBString arginfo stubs 2019-10-06 17:45:32 +02:00