summaryrefslogtreecommitdiff
path: root/Zend/zend_object_handlers.c
Commit message (Collapse)AuthorAgeFilesLines
* Optimized object conversion to array without rebulding properties HashTableDmitry Stogov2021-03-011-0/+32
|
* Change the order of properties used for var_dump(), serialize(), comparison, ↵Dmitry Stogov2021-03-011-33/+21
| | | | | | etc. Now properties are ordered according to their layout in zend_object structure.
* Fixed bug #53826Nikita Popov2021-02-181-18/+23
| | | | | We should handle the case where the method doesn't exist, and where it is not visible the same way.
* Merge branch 'PHP-8.0'Nikita Popov2021-02-161-0/+5
|\ | | | | | | | | * PHP-8.0: Fixed bug #80723
| * Fixed bug #80723Nikita Popov2021-02-161-0/+5
| | | | | | | | | | This fixes the issue just for the Socket class. Presumably we'll want to do the same for other "resource" objects.
* | Replace zend_bool uses with boolNikita Popov2021-01-151-5/+5
|/ | | | | | | We're starting to see a mix between uses of zend_bool and bool. Replace all usages with the standard bool type everywhere. Of course, zend_bool is retained as an alias.
* Fix leak when setting dynamic property on generatorNikita Popov2020-10-161-2/+3
|
* Merge branch 'PHP-7.4'Nikita Popov2020-09-151-2/+2
|\ | | | | | | | | * PHP-7.4: Fix assumption about property guard hash value
| * Fix assumption about property guard hash valueNikita Popov2020-09-151-2/+2
| | | | | | | | | | | | | | | | The "member" string here does not necessarily have a pre-calculated hash value. In particular this is not the case if the class has no properties. Fixes oss-fuzz #25546.
* | Add GC_TRY_ADDREF macroNikita Popov2020-09-151-4/+4
| | | | | | | | | | That adds a ref if not immutable. Also audit uses of GC_IMMUTABLE to either use GC_TRY_ADDREF or GC_TRY_PROTECT_RECURSION.
* | Merge branch 'PHP-7.4'Nikita Popov2020-09-011-3/+10
|\ \ | |/ | | | | | | * PHP-7.4: Check for null EX(func) in write_property
| * Check for null EX(func) in write_propertyNikita Popov2020-09-011-3/+10
| | | | | | | | | | | | | | | | This can happen if zend_call_function inserted a dummy frame, and we already switched to the dummy frame in leave_helper, and an exception is thrown during CV destruction. Fixes oss-fuzz #25343.
* | Merge branch 'PHP-7.4'Nikita Popov2020-08-311-1/+2
|\ \ | |/ | | | | | | * PHP-7.4: Fix bug #80037
| * Fix bug #80037Nikita Popov2020-08-311-1/+2
| | | | | | | | | | | | | | | | | | | | | | If we're accessing an uninitialized typed property and __get is defined, don't perform a read_property callback, as __get is supposed to have no effect on uninitialized typed properties. Usually it doesn't, but by-reference assignments cannot be performed through read_property. I'm deleting the test for bug #80039 again, as it doesn't really make sense anymore with this fix.
* | Implement named parametersNikita Popov2020-07-311-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From an engine perspective, named parameters mainly add three concepts: * The SEND_* opcodes now accept a CONST op2, which is the argument name. For now, it is looked up by linear scan and runtime cached. * This may leave UNDEF arguments on the stack. To avoid having to deal with them in other places, a CHECK_UNDEF_ARGS opcode is used to either replace them with defaults, or error. * For variadic functions, EX(extra_named_params) are collected and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS. RFC: https://wiki.php.net/rfc/named_params Closes GH-5357.
* | Merge branch 'PHP-7.4'Nikita Popov2020-07-151-1/+5
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #79862
| * Fixed bug #79862Nikita Popov2020-07-151-1/+5
| | | | | | | | | | While normally a private property in the active scope would take priority, we should not use this if it has the wrong "staticness".
* | Review the usage of apostrophes in error messagesMáté Kocsis2020-07-101-6/+13
| | | | | | | | Closes GH-5590
* | Add flag to forbid dynamic property creation on internal classesNikita Popov2020-06-241-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While performing resource -> object migrations, we're adding defensive classes that are final, non-serializable and non-clonable (unless they are, of course). This path adds a ZEND_ACC_NO_DYNAMIC_PROPERTIES flag, that also forbids the creation of dynamic properties on these objects. This is a subset of #3931 and targeted at internal usage only (though may be extended to userland at some point in the future). It's already possible to achieve this (what the removed WeakRef/WeakMap code does), but there's some caveats: First, this simple approach is only possible if the class has no declared properties, otherwise it's necessary to special-case those properties. Second, it's easy to make it overly strict, e.g. by forbidding isset($obj->prop) as well. And finally, it requires a lot of boilerplate code for each class. Closes GH-5572.
* | Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)Christoph M. Becker2020-06-161-1/+1
| | | | | | | | | | | | | | | | | | Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce `ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)` to mark unreachable code does no longer trigger C4715[1] warnings in debug builds. This may be useful for other compilers as well. [1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
* | Back up fake_scope in zend_call_functionNikita Popov2020-06-091-27/+0
| | | | | | | | | | | | We regularly find new places where we forgot to reset fake_scope. Instead of having to handle this for each caller of zend_call_function() and similar APIs, handle it directly in zend_call_function().
* | Add zend_call_known_function() API familyNikita Popov2020-06-091-97/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the following APIs: void zend_call_known_function( zend_function *fn, zend_object *object, zend_class_entry *called_scope, zval *retval_ptr, int param_count, zval *params); void zend_call_known_instance_method( zend_function *fn, zend_object *object, zval *retval_ptr, int param_count, zval *params); void zend_call_known_instance_method_with_0_params( zend_function *fn, zend_object *object, zval *retval_ptr); void zend_call_known_instance_method_with_1_params( zend_function *fn, zend_object *object, zval *retval_ptr, zval *param); void zend_call_known_instance_method_with_2_params( zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2); These are used to perform a call if you already have the zend_function you want to call. zend_call_known_function() is the base API, the rest are just really thin wrappers around it for the common case of instance method calls. Closes GH-5692.
* | Merge branch 'PHP-7.4'Nikita Popov2020-06-091-0/+3
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #79683
| * Fixed bug #79683Nikita Popov2020-06-091-0/+3
| | | | | | | | | | | | | | Reset fake_scope during __toString() call. I'll check if we can solve this more globally in master, by resetting fake_scope in zend_call_function.
* | Fix expression warnings and break warningstwosee2020-06-071-1/+1
| | | | | | | | Close GH-5675.
* | Convert Exception::getMessage() result to stringNikita Popov2020-05-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | We specify that the return type of Exception::getMessage() is a string. However, we don't currently ensure this, because Exception::$message is a protected member that can be set to any type. Fix this by performing an explicit type-cast. This also requires a temporary refcount increment in the __toString() object handler, because there is no additional owner of the object, and it may get released prematurely as part of the __toString() call.
* | Fix [-Wundef] warning in Zend folderGeorge Peter Banyard2020-05-121-1/+1
| |
* | Use correct variableGeorge Peter Banyard2020-05-051-1/+1
| | | | | | | | This seems to stem from a copy paste, however there is no object variable in this function
* | Make cast_object handler requiredNikita Popov2020-03-311-34/+30
| | | | | | | | | | | | | | | | Avoid subtle differences in behavior depending on whether the handler is absent or returns FAILURE. If you previously set cast_object to NULL, create a handler that always returns FAILURE instead.
* | Add a ZEND_UNCOMPARABLE valueNikita Popov2020-03-311-2/+2
| | | | | | | | | | | | To explicitly indicate that objects are uncomparable. For now this has no functional difference from the usual 1 return value, but makes intent clearer.
* | Report object cast failures internallyNikita Popov2020-03-311-27/+35
| | | | | | | | | | | | | | | | | | | | | | Make cast_object return FAILURE for casts to int/float, rather than throwing a notice and returning SUCCESS. Instead move the emission of the notice to the code invoking cast_object. This will allow us to customize the behavior per call-site. This change is written to be NFC, and the code in zend_std_compare_objects() should illustrate the current behavior doesn't make a lot of sense.
* | Simplify __call fetching for static methodsNikita Popov2020-01-211-6/+2
| | | | | | | | | | If we have a __call on a parent, we should always also have a __call on the child, so there's no need to perform this walk.
* | Merge branch 'PHP-7.4'Nikita Popov2019-12-091-2/+15
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #78904: Don't call any magic for uninitialized typed properties
| * Fixed bug #78904: Don't call any magic for uninitialized typed propertiesNikita Popov2019-12-091-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | We already changed the behavior for __set() in f1848a4. However, it seems that this is also a problem for all the other property magic, see bug #78904. This commit makes the behavior of all the property magic consistent: Magic will not be triggered for uninitialized typed properties, only explicitly unset() ones. This brings behavior more in line how non-typed properties behave and avoids WTF. Closes GH-4974.
* | Merge branch 'PHP-7.4'Nikita Popov2019-11-151-2/+10
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #78810
| * Fixed bug #78810Nikita Popov2019-11-151-2/+10
| |
* | Remove support for array_key_exists() with objectsNikita Popov2019-11-041-1/+0
| |
* | Merge branch 'PHP-7.4'Nikita Popov2019-10-251-0/+7
|\ \ | |/ | | | | | | * PHP-7.4: Fix bug #78226: Don't call __set() on uninitialized typed properties
| * Fix bug #78226: Don't call __set() on uninitialized typed propertiesNikita Popov2019-10-251-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Assigning to an uninitialized typed property will no longer trigger a call to __set(). However, calls to __set() are still triggered if the property is explicitly unset(). This gives us both the behavior people generally expect, and still allows ORMs to do lazy initialization by unsetting properties. For PHP 8, we should fine a way to forbid unsetting of declared properties entirely, and provide a different way to achieve lazy initialization.
* | Optimize instanceof_functionNikita Popov2019-10-251-4/+4
| | | | | | | | | | | | | | | | Split out the simple equality check into an inline function -- this is one of the common cases. Replace instanceof_function_ex with zend_class_implements_interface. There are a few more places where it may be used.
* | Merge branch 'PHP-7.4'Nikita Popov2019-10-101-0/+2
|\ \ | |/
| * Return error_zval form get_property_ptr_ptr on exceptionNikita Popov2019-10-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | This goes in the reverse direction of 4463acb9513dfb62206760c49b3da1fe4d92f40a. After looking around a bit, it seems that we already check for Z_ISERROR_P() on the get_property_ptr_ptr return value in other places. So do this in zend_fetch_property_address() as well, and also make sure that EG(error_zval) is indeed returned on exception in get_property_ptr_ptr. In particular, this fixes the duplicate exceptions that we used to get because first get_property_ptr_ptr threw one and then read_property throws the same exception again.
* | Comparison cleanup:Dmitry Stogov2019-10-071-9/+32
| | | | | | | | | | - introduce zend_compare() that returns -1,0,1 dirctly (without intermediate zval) - remove compare_objects() object handler, and keep only compare() handler
* | Convert some notices to warningsNikita Popov2019-10-021-3/+3
| | | | | | | | Part of https://wiki.php.net/rfc/engine_warnings.
* | Add check_only parameter to get_closure handlerChristoph M. Becker2019-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | `get_closure` handlers are called to check whether an object is callable, and to actually get the closure, respectively. The behavior of the handler might differ for these two cases, particularly the handler may throw in the latter case, but should not in the former. Therefore we add a `check_only` parameter, to be able to distinguish the desired purpose.
* | Use ZEND_TYPE_IS_SET() when checking for property typesNikita Popov2019-09-231-2/+2
| | | | | | | | | | Instead of a simple if or 0 comparison. This would no longer work if zend_type is a struct.
* | Detect calls to abstract methods in get_method() alreadyNikita Popov2019-09-061-0/+16
| | | | | | | | | | | | | | | | | | | | Instead of checking for this during DO_FCALL, already detect this case during get_method()/get_static_method(), similar to visibility checks. This causes a minor difference in behavior, in that arguments will no longer be evaluated. I think this is correct though (and consistent with visibility errors).
* | Merge branch 'PHP-7.4'Dmitry Stogov2019-08-081-0/+5
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #78379 (Cast to object confuses GC, causes crash)
| * Merge branch 'PHP-7.3' into PHP-7.4Dmitry Stogov2019-08-081-0/+5
| |\ | | | | | | | | | | | | * PHP-7.3: Fixed bug #78379 (Cast to object confuses GC, causes crash)
| | * Merge branch 'PHP-7.2' into PHP-7.3Dmitry Stogov2019-08-081-0/+5
| | |\ | | | | | | | | | | | | | | | | * PHP-7.2: Fixed bug #78379 (Cast to object confuses GC, causes crash)