Commit Graph

2587 Commits

Author SHA1 Message Date
Nikita Popov
5fc70243d7 Add missing addref for MATCH_ERROR operand 2020-07-10 15:58:42 +02:00
Ilija Tovilo
9fa1d13301
Implement match expression
RFC: https://wiki.php.net/rfc/match_expression_v2

Closes GH-5371.
2020-07-09 23:52:17 +02:00
Nikita Popov
2af1d36bc5 Skip special function optimization for redeclared disabled functions
As pointed out on GH-5817.
2020-07-08 10:11:00 +02:00
Nikita Popov
1e39469678 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79783
2020-07-07 09:57:07 +02:00
Nikita Popov
971e5c5186 Fixed bug #79783
Make sure we don't drop the by-reference check when passing the
result of a VM builtin function.
2020-07-07 09:56:14 +02:00
moliata
4a0d6901bb refactor: class constants parsing
As part of my work on typed class constants, I wanted to make a
separate pull request for unrelated changes.

These include:

 * Moving from ast->child[0]->attr to ast->attr
 * Making zend_ast_export_ex() export class constants' visibility
 * Extracting an additional zend_compile_class_const_group() function

Closes GH-5812.
2020-07-06 18:34:41 +02:00
Nikita Popov
6a195cacf3 Treat attribute argument lists like normal argument lists
Allow trailing comma. Syntactically allow unpacking, but forbid it
during compilation.

The trailing comma test-case is adopted from GH-5796.
2020-07-02 15:27:45 +02:00
Martin Schröder
053ef28b8d Implement Attribute Amendments.
RFC: https://wiki.php.net/rfc/attribute_amendments

Support for attribute grouping is left out, because the short
attribute syntax RFC will likely make it obsolete.

Closes GH-5751.
2020-06-29 10:45:51 +02:00
Nikita Popov
1314ccbf8c Cache __unserialize() instead of unserialize()
We should use these cache slots for the new object serialization
mechanism rather than the old one.
2020-06-26 10:54:40 +02:00
Nikita Popov
c5caa05171 Fixed bug #79740 2020-06-26 10:31:55 +02:00
moliata
48e16a9dba Use ZEND_TOSTRING_FUNC_NAME
Closes GH-5736.
2020-06-18 17:06:19 +02:00
moliata
45d1c38dab Use zend_is_constructor() 2020-06-17 16:46:17 +02:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
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>
2020-06-16 18:39:09 +02:00
twosee
83a77015ad Add helper APIs for maybe-interned string creation
Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using
ZVAL_INTERNED_STRING and ZSTR_CHAR.

Add zend_string_init_fast() as a helper for the empty string /
one char interned string / zend_string_init() pattern.

Also add corresponding ZVAL_STRINGL_FAST etc macros.

Closes GH-5684.
2020-06-08 15:31:52 +02:00
Nikita Popov
b03cafd19c Fix bug #77966: Cannot alias a method named "namespace"
This is a bit tricky: In this cases we have "namespace as", which
means that we will only recognize "namespace" as an identifier when
the lookahead token is already at the "as". This means that
zend_lex_tstring picks up the wrong identifier.

We solve this by actually assigning the identifier as the semantic
value on the parser stack -- as in almost all cases we will not
actually need the identifier, this is just an (offset, size)
reference, not a copy of the string.

Additionally, we need to teach the lexer feedback mechanism used
by tokenizer TOKEN_PARSE mode to apply feedback to something
other than the very last token. To that purpose we pass through
the token text and check the tokens in reverse order to find the
right one.

Closes GH-5668.
2020-06-08 12:55:14 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00
twosee
7d6a0ba808 Fix expression warnings and break warnings
Close GH-5675.
2020-06-07 10:41:11 +02:00
Nikita Popov
064b464448 Implement "Constructor Promotion" RFC
RFC: https://wiki.php.net/rfc/constructor_promotion

Closes GH-5291.
2020-06-05 15:15:51 +02:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00
Máté Kocsis
dd6e54b746
Fix #79652 Ensure that the mixed type is displayed instead of the union of all types
Closes GH-56430
2020-05-30 08:58:59 +02:00
Nikita Popov
baa285881f Fix variable type
This is no longer a boolean.
2020-05-26 15:58:36 +02:00
Tyson Andre
9b33272536 Allow generators to have a real return type of mixed or object
Fixes an edge case overlooked in
https://github.com/php/php-src/pull/5313

Generators are objects, so `object` should have also been allowed in addition to
`iterable` and `Traversable`

Closes GH-5626
2020-05-26 09:57:10 -04:00
Max Semenik
23ee4d4b57 Support catching exceptions without capturing them to variables
RFC: https://wiki.php.net/rfc/non-capturing_catches

Closes GH-5345.
2020-05-26 15:12:18 +02:00
George Peter Banyard
c803499e23 Remove depreacted curly brace offset syntax
Closes GH-5221
2020-05-22 16:52:17 +02:00
Máté Kocsis
aec4c0fd03
Add support for the mixed type
RFC: https://wiki.php.net/rfc/mixed_type_v2
Closes GH-5313

Co-authored-by: Dan Ackroyd <danack@basereality.com>
2020-05-22 16:08:12 +02:00
Nikita Popov
c2068e95b4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #79603, by retrying on RTD key collision
2020-05-20 11:24:37 +02:00
Nikita Popov
4f47ba99f0 Fix bug #79603, by retrying on RTD key collision
This is a non-intrusive fix for 7.4, still trying to find a good
solution for master.

Closes GH-5597.
2020-05-20 11:22:50 +02:00
Nikita Popov
c6a6ca078b Use zend_zval_type_name() API where possible
Rather than zend_get_type_by_const(Z_TYPE_P()).
2020-05-13 14:56:05 +02:00
Nikita Popov
5bc1e224db Make numeric operations on resources, arrays and objects type errors
RFC: https://wiki.php.net/rfc/arithmetic_operator_type_checks

Closes GH-5331.
2020-05-05 16:11:13 +02:00
Nikita Popov
53eee290b6 Completely remove disabled functions from function table
Currently, disabling a function only replaces the internal
function handler with one that throws a warning, and a few
places in the engine special-case such functions, such as
function_exists. This leaves us with a Schrödinger's function,
which both does not exist (function_exists returns false) and
does exist (you cannot define a function with the same name).
In particular, this prevents the implementation of robust
polyfills, as reported in https://bugs.php.net/bug.php?id=79382:

    if (!function_exists('getallheaders')) {
        function getallheaders(...) { ... }
    }

If getallheaders() is a disabled function, this code will break.

This patch changes disable_functions to remove the functions from
the function table completely. For all intents and purposes, it
will look like the function does not exist.

This also renders two bits of PHP functionality obsolete and thus
deprecated:

 * ReflectionFunction::isDisabled(), as it will no longer be
   possible to construct the ReflectionFunction of a disabled
   function in the first place.
 * get_defined_functions() with $exclude_disabled=false, as
   get_defined_functions() now never returns disabled functions.

Fixed bug #79382.

Closes GH-5473.
2020-04-30 09:53:57 +02:00
Gabriel Caruso
34c460f329
Check __set_state structure
Fix Bug #79521.

Closes GH-5462.
2020-04-28 17:02:03 +02:00
Gabriel Caruso
7ce8c5ad89
Slipt error messages while checking magic methods attributes
Closes GH-5465
2020-04-27 16:32:00 +02:00
Nikita Popov
19e886d9d8 Avoid throw expression leaks
Mark "throw" used in expression context with a flag, and don't
treat it as a BB terminator in that case. This prevents us from
optimizing away the following opcodes as unreachable, which may
result in live ranges being dropped incorrectly.

Close GH-5450.
2020-04-27 15:22:05 +02:00
Nikita Popov
fd00c7cf10 Pass existing lcname to check_magic_method_implementation 2020-04-27 12:33:29 +02:00
Levi Morrison
90db6f2cc5 Add case insensitive find_ptr hash functions
- zend_hash_find_ptr_lc(ht, zend_string *key)
 - zend_hash_str_find_ptr_lc(ht, const char *str, size_t len)

Note that zend_hash_str_find_ptr_lc used to exist in zend_compile.c
as        zend_hash_find_ptr_lc. When exporting this I figured it
was best to use the same conventions as the rest of zend_hash.h.
2020-04-26 23:29:41 +02:00
Gabriel Caruso
6f908a0bf4
Check Serialization magic methods structure
Closes GH-5441
2020-04-26 02:16:39 +02:00
Nikita Popov
786e0ae574 Use zend_make_tmp_result() helper in more places 2020-04-24 12:10:06 +02:00
Nikita Popov
f264bf2d69 Accept result znode in zend_compile_class_decl()
Make this use the same pattern we use everywhere else.
2020-04-24 12:04:54 +02:00
Ilija Tovilo
f65240759f Use return in compile_expr for consistency 2020-04-24 12:01:10 +02:00
Ilija Tovilo
0810fcd0d0 Make throw statement an expression
RFC: https://wiki.php.net/rfc/throw_expression

This has an open issue with temporaries that are live at the time
of the throw being leaked. Landing this now for easier testing and
will revert if we cannot resolve the issue.

Closes GH-5279.
2020-04-23 12:51:23 +02:00
Nikita Popov
08c5c69eff Remove ZEND_ACC_DTOR flag
This is only used in reflection, where doing a simple string check
is acceptable.

I'm also dropping the "dtor" printing in the reflection dump.
Dtors are just one of many magic methods, I don't think there's
a point in explicitly highlighting them, when the name is already
unambiguous.
2020-04-17 15:32:47 +02:00
Gabriel Caruso
b10b73eb86
Fix magic method name 2020-04-16 10:39:25 +02:00
Gabriel Caruso
75a58ba522
Improve error messages for magic methods by appending method's class
Closes GH-5397.
2020-04-16 10:34:58 +02:00
Nikita Popov
4fb705a03d Add zend_string_concat2 API 2020-04-14 17:18:05 +02:00
Nikita Popov
bac5137e4e Add zend_create_member_string() API
This is a recurring pattern.
2020-04-14 16:52:13 +02:00
Nikita Popov
d030ddb2cd Export the zend_string_concat3() API 2020-04-09 15:06:53 +02:00
Nikita Popov
f1dd8b2af0 Make division by zero error check more accurate
For division (rather than modulus) we should check the double
value, otherwise the result might be zero after integer truncation,
but not zero as a floating point value.
2020-04-01 14:47:21 +02:00
Nikita Popov
1ed132e2e5 Unify checks for binary operator errors for ct eval
Move everything into one function and share it with opcache.
This fixes some discrepancies.
2020-04-01 14:42:58 +02:00
Nikita Popov
f74e30c07c Check abstract method signatures coming from traits
RFC: https://wiki.php.net/rfc/abstract_trait_method_validation

Closes GH-5068.
2020-03-26 10:07:22 +01:00
Nikita Popov
df79277de3 Revert "Fetch for read in nested property assignments"
This reverts commit bb43a3822e.

After thinking about this a bit more, this is now going to be
a complete solution for the "readonly properties" case, for example:

    unset($foo->readOnly->bar);

should also be legal and

    $foo->readOnly['bar'] = 42;

should also be legal if $foo->readOnly is not an array but an
ArrayAccess object.

I think it may be better to distinguish better on the BP_VAR flag
level. Reverting for now.
2020-03-18 14:54:43 +01:00