Commit graph

18 commits

Author SHA1 Message Date
Ilija Tovilo
93fc88e808
Fix Enum::from/tryFrom memory leak in JIT for internal enums
when passing an int to a string enum. Previously, the int was coerced to
a string. The JIT skips parameter clean up when unnecessary. In this
particular case, passing int to from(int|string) normally doesn't cause
a coercion so no dtor for the $value zval is generated.

To circumvent this we avoid coersion by explicitly allowing ints and
converting them to strings ourselves. Then we can free it appropriately.

See GH-8518
Closes GH-8633
2022-05-28 10:51:17 +02:00
Ilija Tovilo
2145f80d4b
Register JSON_ERROR_NON_BACKED_ENUM constant (#8285)
Fixes GH-8238
2022-03-31 14:31:17 +02:00
Bob Weinand
cbbf3502a2 Fix GH-8176: Fix leaking enum values in property initializers 2022-03-07 18:26:46 +01:00
Agustin Gomes
8bb19cb549 Add test cases for backed enum implementing interface
In the Enumeration RFC, it states Backed Enums can implement
interfaces, but it was not clear where the backed Enum type
would need to be placed in such situation.

This commit adds a test case for these scenarios.

Signed-off-by: Agustin Gomes <me@agustingomes.com>

Closes GH-7593.
2021-10-20 09:53:51 +02:00
Nikita Popov
bd3e536383 Fixed bug #81514
Objects reuse the GC_PERSISTENT flag as IS_OBJ_WEAKLY_REFERENCED,
which we did not account for in ZVAL_COPY_OR_DUP. To make things
worse the incorrect zval_copy_ctor_func() invocation silently did
nothing. To avoid that, add an assertion that it should only be
called with arrays and strings (unlike the normal zval_copy_ctor()
which can be safely called on any zval).
2021-10-08 10:31:24 +02:00
Nikita Popov
a942b284e6 Fixed bug #81465
Make the error message for enum cases more technically correct.
2021-09-23 14:29:27 +02:00
Máté Kocsis
805f2b9803
Fix forgotten test 2021-09-02 17:44:52 +02:00
Michael Voříšek
3398efa597
Fix typo in enum test (#7368)
Fix typo in enum test and test create prop with typed enum.
2021-08-14 09:53:37 +02:00
Nikita Popov
a027247289 Fix message in test
Looks like I did not "git add" the message update.

Also drop the now dead ZEND_ENUM_PROPERTY_ERROR() macro while
here.
2021-08-13 17:01:16 +02:00
Nikita Popov
caefc6a507 Don't use custom object handlers for enum properties
Instead mark name/value as readonly and the class as
NO_DYNAMIC_PROPERTIES. This gives us the desired limitations
using native features.

In fact, this also fixes a bug where opcache cache slot merging
might result in a write to the name/value properties being
allowed. The readonly implementation handles this case correctly.
2021-08-13 16:44:39 +02:00
Jeremy Mikola
858d0c0916 Include class name in Serializable deprecation message
The deprecation message was originally introduced in 3e6b447 (#6494).

I first encountered this notice when testing the MongoDB extension
with PHP 8.1, which produced many duplicate messages that provided
no detail about the particular class that needed to be fixed.

Closes GH-7346.
2021-08-11 10:35:47 +02:00
Máté Kocsis
663536d7d9
Improve class inheritance error messages (#7307) 2021-07-27 09:42:37 +02:00
Nikita Popov
a374230c15 Add support for internal enums
This adds support for internal enums with the same basic approach
as userland enums. Enum values are stored as CONSTANT_AST and
objects created during constant updating at runtime. This means
that we need to use mutable_data for internal enums.

This just adds basic support and APIs, it does not include the
stubs integration from #7212.

Closes GH-7302.
2021-07-27 09:19:14 +02:00
Máté Kocsis
75a678a7e3
Declare tentative return types for Zend (#7251)
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 13:44:20 +02:00
Tyson Andre
e00b3ec6ae
Fix false positive recursion warning for var_export of enums (#7201) 2021-06-26 15:33:39 -04:00
Máté Kocsis
5beba0b038
Declare tentative return types for ext/json (#7051) 2021-05-27 10:47:15 +02:00
Nikita Popov
3e6b447979 Partially deprecate Serializable
If Serializable is implemented, require that __serialize() and
__unserialize() are implemented as well, else issue a deprecation
warning.

Also deprecate use of PDO::FETCH_SERIALIZE.

RFC: https://wiki.php.net/rfc/phase_out_serializable

Closes GH-6494.
2021-04-28 16:55:14 +02:00
Ilija Tovilo
269c8dac1d
Implement enums
RFC: https://wiki.php.net/rfc/enumerations

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>

Closes GH-6489.
2021-03-17 19:08:03 +01:00