Commit graph

1045 commits

Author SHA1 Message Date
Dmitry Stogov
f6d7f78a9b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix ext/zend_test/tests/observer_bug81430_2.phpt failure
2022-01-12 12:09:28 +03:00
Dmitry Stogov
f7c3f6e7e2 Fix ext/zend_test/tests/observer_bug81430_2.phpt failure 2022-01-12 12:08:59 +03:00
Christoph M. Becker
a8c6a5cef6
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix #81430: Attribute instantiation leaves dangling pointer
2022-01-10 12:42:43 +01:00
Christoph M. Becker
4833362844
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #81430: Attribute instantiation leaves dangling pointer
2022-01-10 12:42:18 +01:00
Benjamin Eberlei
2f6a06ccb0
Fix #81430: Attribute instantiation leaves dangling pointer
By switching attribute constructor stackframe to be called via
trampoline the stack allocation is not causing dangling pointers
in the zend_observer API anymore.

Co-Authored-By: Florian Sowade <f.sowade@suora.com>
Co-Authored-By: Christopher Becker <cmbecker69@gmx.de>
Co-Authored-By: Dmitry Stogov <dmitry@zend.com>

Closes GH-7885.
2022-01-10 12:40:15 +01:00
Christoph M. Becker
2658925e60
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix #81681: ReflectionEnum throwing exceptions
2021-12-02 23:22:47 +01:00
Christoph M. Becker
59dd4fd742
Fix #81681: ReflectionEnum throwing exceptions
Enums are neither instantiable nor cloneable.

Closes GH-7707.
2021-12-02 23:22:07 +01:00
Nikita Popov
aaba0000d3 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix bug #81630: Don't claim known hash in getTraitAliases()
  Assert hash is known when we claim it is
2021-11-17 15:55:25 +01:00
Nikita Popov
6641e3b8f4 Fix bug #81630: Don't claim known hash in getTraitAliases()
We don't intern this string, and this code is not particularly
performance critical in the first place, so just drop the the
assumption.
2021-11-17 15:54:42 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
fb5cff1272 Print array defaults in reflection
As a followup to f34114b1fb print
the contents of arrays rather than just a generic "Array" marker.
Also drop the truncation on strings. As we no longer resolve
constants, there should be less concerns about printing very
large strings here. If someone thought it was a good idea to use
a 10k character strings as a default value in code, then it should
be fine for us to print it in reflection as well.
2021-10-20 15:16:29 +02:00
Nikita Popov
11d97ae00c Remove unused scope argument 2021-10-20 14:55:00 +02:00
sasezaki
e286313fa7 Fix bug #81474: Make ReflectionAttribute non-final
This backports GH-7520 to PHP 8.0.

Closes GH-7545.
2021-10-04 14:39:46 +02:00
Nikita Popov
f34114b1fb Export AST for default value strings in reflection
When dumping default values in ReflectionXXX::__toString(), for
expression initializers print the AST export instead of trying to
evaluate the expression. With the introduction of "new in
initializers" the result of the evaluation will commonly not be
printable at all, and "__toString" will throw an exception, which
is not particularly useful. Using the AST export also provides more
information on how the parameter was originally declared, e.g. it
preserves the fact that a certain constant was used.

Closes GH-7540.
2021-10-01 16:13:35 +02:00
Nikita Popov
ea11e79a43 Fixed bug #81457
When Reflection internally instantiates a ReflectionClass, it
should create a more specific ReflectionEnum instance if the
class is actually an enum.
2021-09-20 15:29:30 +02:00
Nikita Popov
315f40942b
Always use CE_CACHE, remove TYPE_HAS_CE (#7336)
Currently, CE_CACHE on strings is only used with opcache interned strings. This
patch extends usage to non-opcache interned strings as well. This means that
most type strings can now make use of CE_CACHE even if opcache is not loaded,
which allows us to remove TYPE_HAS_CE kind, and fix some discrepancies
depending on whether a type stores a resolved or non-resolved name.

There are two cases where CE_CACHE will not be used:

 * When opcache is not used and a permanent interned string (that is not an
   internal class name) is used as a type name during the request. In this case
   we can't allocate a map_ptr index for the permanent string, as it would be
   not be in the permanent map_ptr index space.
 * When opcache is used but the script is not cached (e.g. eval'd code or
   opcache full). If opcache is used, we can't allocate additional map_ptr
   indexes at runtime, because they may conflict with indexes allocated by
   opcache.

In these two cases we would end up not using CE caching for property types
(argument/return types still have the separate cache slot).
2021-08-11 10:28:52 +02:00
Nikita Popov
a4e206808c Use zend_string_equals_literal_ci() 2021-08-10 15:52:28 +02:00
Joe Watkins
05ef6334cd
Fix bug #81303 improve match errors 2021-08-02 17:31:26 +02:00
Máté Kocsis
8d25b62414
Display the readonly property modifier when printing reflection info 2021-07-25 12:13:48 +02:00
Nikita Popov
6d505d4445 Add RETURN/RETVAL_COPY_DEREF() macros
These were missing from the set...

I think quite a few of these usages don't actually need the DEREF,
but I've just kept things as is for now.
2021-07-22 09:44:19 +02:00
Levi Morrison
ae8647d9d3
Remove leading underscore for _zend_hash_find_known_hash (#7260)
Convert zend_hash_find_ex(..., 1) to zend_hash_find_known_hash(...)
Convert zend_hash_find_ex(..., 0) to zend_hash_find(...)

Also add serializable changes to UPGRADING.INTERNALS summary
2021-07-20 17:07:17 -06:00
Joe Watkins
27bb57356c
Merge branch 'master' of github.com:php/php-src
* 'master' of github.com:php/php-src:
  Implement readonly properties
2021-07-20 12:32:51 +02:00
Joe Watkins
570d9b63e9
Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Nikita Popov
6780aaa532 Implement readonly properties
Add support for readonly properties, for which only a single
initializing assignment from the declaring scope is allowed.

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

Closes GH-7089.
2021-07-20 12:05:46 +02:00
Nikita Popov
882289eb9e Fix leak if attribute arg evaluation fails while printing 2021-07-14 09:15:52 +02:00
Marco Pivetta
6e16e1daa9 Make ReflectionProperty/Method always accessible
With this patch, it is no longer required to call
`ReflectionProperty#setAccessible()` or
`ReflectionMethod#setAccessible()` with `true`.

If a userland consumer already got to the point of accessing
object/class information via reflection, it makes little sense
for `ext/reflection` to disallow accessing `private`/`protected`
symbols by default.

After this patch, calling `ReflectionProperty#setAccessible(true)`
or `ReflectionMethod#setAccessible(true)` on newly instantiated
`ReflectionProperty` or `ReflectionMethod` respectively will have
no effect.

RFC: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op

Closes GH-5412.
2021-07-08 10:55:38 +02:00
Benjamin Eberlei
bc39abe8c3 Fix #80097: Have ReflectionAttribute implement Reflector and __toString
Implement printing for ReflectionAttribute. Attributes aren't
printed as part of reflection output for other structures (classes
etc) yet.

Closes GH-6117.
2021-07-07 12:42:04 +02:00
Máté Kocsis
a5360e80c2
Add support for final class constants
RFC: https://wiki.php.net/rfc/final_class_const

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-06 21:42:38 +02:00
Nikita Popov
f43a19ee94 Slightly clean up reflection constant printing
The basic formatting is always the same, the only thing that
differs is how the value is printed, so don't duplicate the rest.
2021-07-06 16:25:05 +02:00
George Peter Banyard
069a9fa5e4
Pure Intersection types (#6799)
Implement pure intersection types RFC

RFC: https://wiki.php.net/rfc/pure-intersection-types

Co-authored-by: Nikita Popov <nikic@php.net>
Co-authored-by: Ilija Tovilo <ilutov@php.net>
2021-07-05 14:11:03 +02:00
Nikita Popov
adfa585109 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #81208
2021-07-01 13:37:53 +02:00
Nikita Popov
b976bc44f1 Fixed bug #81208
The number of populated positional arguments is argc. i may also
include named args and thus try to dtor uninitialized zvals.
2021-07-01 13:36:57 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Joe Watkins
aad0d26816
Fix bug #81200 ReflectionMethod::isStatic belongs on ReflectionFunctionAbstract 2021-06-28 09:49:30 +02:00
Aaron Piotrowski
859524c246
Remove fiber context embedding 2021-06-14 14:34:36 -05:00
Tyson Andre
9a0cc69c53
Use 16 instead of 15 bytes of random data in ReflectionReference->getId (#7148)
```
ZEND_BEGIN_MODULE_GLOBALS(reflection)
	bool key_initialized;
	unsigned char key[REFLECTION_KEY_LEN];
ZEND_END_MODULE_GLOBALS(reflection)
```

This was previously also overwriting key_initialized, which didn't matter at all
because C struct layout is always in order of declaration and the value of
key_initialized was subsequently set to 1.
2021-06-13 16:04:37 -04:00
Aaron Piotrowski
e6e6b3e68b
Improve fiber interoperability (#7128) 2021-06-10 23:00:07 -05:00
Martin Schröder
a65989b127
Alternative Fiber Internals Refactoring (#7101) 2021-06-04 23:25:35 -05:00
Aaron Piotrowski
d2e5203865
Split fiber status and flags (#7094)
Co-Authored-By: twosee <twose@qq.com>
2021-06-03 15:34:48 -05:00
Joe Watkins
b227a72285
ReflectionFunctionAbstract::getClosureUsedVariables
Make a distinction at compile time between bind types for static
  variables

  getStaticVariables remains unchanged

  Fixes #80071
2021-05-21 15:25:35 +02:00
Máté Kocsis
532c60cb92
Add support for tentative return types of internal methods
RFC: https://wiki.php.net/rfc/internal_method_return_types

Closses GH-6971
2021-05-14 15:55:25 +02:00
Nikita Popov
50b4a7adf9 Property handle unset name on ReflectionClassConstant
While the typed property ensures that the value is a string,
we should make sure that we handle an unset property gracefully.

Do this by throwing the same error we would normally throw if
you access an uninitializde typed property.
2021-05-07 12:39:17 +02:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Aaron Piotrowski
810fb59f66
Improve fiber backtraces
The start/resume/throw execute_data is now attached as the prev_execute_data to the bottom frame of the fiber stack when the fiber is running.
2021-04-30 12:17:50 -05:00
Nikita Popov
5295e368b4 Filter return value of ReflectionClassConstant::getModifiers()
Don't return internal flags like IS_CASE.
2021-04-28 14:55:37 +02:00
Nikita Popov
fd1d5ec2b4 Add ZEND_CLASS_CONST_FLAGS() macro
And drop Z_ACCESS_FLAGS(). We no longer store *only* access flags
in these.
2021-04-28 14:51:54 +02:00
Aaron Piotrowski
c276c16b66
Implement Fibers
RFC: https://wiki.php.net/rfc/fibers

Closes GH-6875.
2021-04-26 11:07:06 -05:00
Matt Brown
6cd0b48cac Implement never return type
The never type can be used to indicate that a function never
returns, for example because it always unwinds.

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

Closes GH-6761.
2021-04-19 11:27:29 +02:00
Dmitry Stogov
4dcde9cf18 Don't evalutae ZEND_AST_CLASS_CONST to ZEND_AST_CONSTANT ar
compile-time. Keep at to run-time and use Fast Class Cache during
run-time evaluation.
2021-04-09 17:48:28 +03:00
Dmitry Stogov
d8e4fbae62 Fast Class Cache
This is generalization of idea, that was previously usesd for caching
resolution of class_entries in zend_type. Now very similar mechanizm is
used for general zend_string into zend_class_entry resolution.

Interned zend_string with IS_STR_CLASS_NAME_MAP_PTR GC_FLAG uses its
refcount to adress corresponding zend_class_entry cache slot.
The refcount keeps an offset to this slot from CG(map_ptr_base).
Flag may be checked by ZSTR_HAS_CE_CACHE(str), cache slot may be read by
ZSTR_GET_CE_CACHE(str) and set by ZSTR_SET_CE_CACHE(str, ce).
2021-04-08 23:37:40 +03:00