Commit Graph

482 Commits

Author SHA1 Message Date
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Christoph M. Becker
4b1feda574
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9905: constant() behaves inconsistent when class is undefined
2022-11-09 15:23:21 +01:00
Christoph M. Becker
b2186ca7c4
Fix GH-9905: constant() behaves inconsistent when class is undefined
Directly referring to a constant of an undefined throws an exception;
there is not much point in `constant()` raising a fatal error in this
case.

Closes GH-9907.
2022-11-09 15:21:50 +01:00
Michael Voříšek
60189aa96a
Skip locale tests /w musl libc (#9141) 2022-07-25 23:56:14 +01:00
Nikita Popov
902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00
Kamil Tekiela
c3dda473cc
Fix 'can not' in test data and in code comments 2021-10-05 09:51:58 +01: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
Ayesh Karunaratne
b8e380ab09 Update deprecation message for incompatible float to int conversion
Updates the deprecation message for implicit incompatible float to int conversion from:

```
Implicit conversion from non-compatible float %.*H to int in %s on line %d
```

to

```
Implicit conversion from float %.*H to int loses precision in %s on line %d
```

Related: #6661
2021-06-07 14:36:11 +02:00
George Peter Banyard
b6958bb847
Implement "Deprecate implicit non-integer-compatible float to int conversions" RFC. (#6661)
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-05-31 15:48:45 +01:00
Nikita Popov
e9b005158f Fix output buffer discard on memory limit
Move this code directly into the error handler, and check the
heap->overflow flag. Discarding output here allows us to print
the normal memory limit message to standard output. Otherwise
nothing would be printed unless a different log medium was used,
which makes for a suboptimal debugging experience.
2021-05-31 16:30:36 +02:00
Peter van Dommelen
3a4ea6cb91 Don't automatically adjust memory_limit to 2M
As PHP has a minimum memory usage of 2M (size of allocator chunk),
setting a limit below that value is not meaningful and will be
automatically rounded up to the chunk size. Rather than doing this
silently, show the newly introduced error message.

The memory limit had to be increased to 2M for a number of tests.

tests/lang/bug45392 has been marked as XFAIL. This old bugfix is
not working as intended. The memory limit in main's `PG(memory_limit)`
differs from the one in zend_alloc. In zend_alloc the `AG(mm_heap)->limit`
is defined as `max(passed_value, ZEND_MM_CHUNK_SIZE)`. The check made in
an unclean shutdown will never be true unless the memory limit is lower
than ZEND_MM_CHUNK_SIZE, which happened to be the case in the test.
https://bugs.php.net/bug.php?id=45392
fcc0fdd125
2021-05-31 15:42:10 +02:00
Nikita Popov
de6e401e05
Use common formatting for backtraces (#6977)
This makes debug_print_backtrace() use the same formatting as exception
backtraces. The only difference is that the final #{main} is omitted,
because it wouldn't make sense for limited backtraces, and wasn't there
previously either.
2021-05-18 11:43:37 +02:00
Máté Kocsis
30a082cb16
Make some exception properties typed
Closes GH-6891
2021-04-22 10:22:50 +02:00
Josh Soref
462da6e09c Fix spelling and grammar mistakes
This PR corrects misspellings identified by the check-spelling action.

The misspellings have been reported at jsoref@b6ba3e2#commitcomment-48946465

The action reports that the changes in this PR would make it happy: jsoref@602417c

Closes GH-6822.
2021-04-13 12:09:37 +02:00
Dmitry Stogov
72c3ededed Change the order of properties used for var_dump(), serialize(), comparison, etc.
Now properties are ordered according to their layout in zend_object structure.
2021-03-01 13:29:49 +03:00
George Peter Banyard
3a4b89661e Remove quicktester
This is barely used and more of a hinderence than anything else

Closes GH-6712
2021-02-25 17:39:31 +00:00
George Peter Banyard
589bdf30b2 Implement Explicit octal notation for integers RFC
RFC: https://wiki.php.net/rfc/explicit_octal_notation

Add an extensive test suits for other variants of integer literals

Closes GH-6360
2021-01-04 21:09:23 +01:00
Nikita Popov
c5401854fc Run tidy
This should fix most of the remaining issues with tabs and spaces
being mixed in tests.
2020-09-18 14:28:32 +02:00
George Peter Banyard
31ef94cd42 Convert Division by 0 warnings to Error per the Engine Warning RFC
Closes GH-6125
2020-09-14 13:40:07 +02:00
Máté Kocsis
9975986b7e
Improve error messages mentioning parameters instead of arguments
Closes GH-5999
2020-09-09 10:47:43 +02:00
Máté Kocsis
7aacc705d0
Add many missing closing PHP tags to tests
Closes GH-5958
2020-08-09 22:03:36 +02:00
Nikita Popov
c48b745f00 Promote "undefined array key" notice to warning
This implements the last remaining part of the
https://wiki.php.net/rfc/engine_warnings RFC.

Closes GH-5927.
2020-08-03 14:40:50 +02:00
George Peter Banyard
b2248789ed Implement 'Saner Numeric Strings' RFC:
RFC: https://wiki.php.net/rfc/saner-numeric-strings

This removes the -1 allow_error mode from is_numeric_string functions and replaces it by
a trailing boolean out argument to preserve BC in a couple of places.

Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit
a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError.

This mostly affects:
 - String offsets
 - Arithmetic operations
 - Bitwise operations

Closes GH-5762
2020-07-29 02:51:09 +01:00
Andrea Faulds
f759936591 Permit trailing whitespace in numeric strings
This is part 1 of the 'Saner Numeric Strings' RFC:
https://wiki.php.net/rfc/saner-numeric-strings
2020-07-29 02:22:38 +01:00
Nikita Popov
acbf7802af Improved number to string comparison semantics
RFC: https://wiki.php.net/rfc/string_to_number_comparison

Closes GH-3886.
2020-07-22 12:23:49 +02:00
Máté Kocsis
5770b66722
Cleanup argument handling of Zend functions and methods
Closes GH-5847
2020-07-21 14:47:03 +02:00
Rowan Tommins
55a15f32ce Improve output of tokens in Parse Errors
Currently, unexpected tokens in the parser are shown as the text
found, plus the internal token name, including the notorious
"unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)".

This commit replaces that with a more user-friendly format, with
two main types of token:

* Tokens which always represent the same text are shown like
  'unexpected token "::"' and 'expected "::"'
* Tokens which have variable text are given a user-friendly
  name, and show like 'unexpected identifier "foo"', and
  'expected identifer'.

A few tokens have special cases:

* unexpected token """ -> unexpected double-quote mark
* unexpected quoted string "'foo'" -> unexpected single-quoted
  string "foo"
* unexpected quoted string ""foo"" -> unexpected double-quoted
  string "foo"
* unexpected illegal character "_" -> unexpected character 0xNN
  (where _ is almost certainly a control character, and NN is the
   hexadecimal value of the byte)

The \ token has a special case in the implementation just to stop
bison making a mess of escaping it and it coming out as \\
2020-07-13 11:07:40 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Ayesh Karunaratne
d114812faf [ci skip] Various typo fixes in stub comments and CHANGES file 2020-06-25 23:32:40 +02:00
twosee
cb2275866d Fix BC break of zend_throw_exception
This also fixes a SegFault

Closes GH-5670
2020-06-06 17:17:44 +02:00
Nikita Popov
e949f306be Fixed bug #72089: Throw Error on require failure
It should be noted that we still throw the usual fopen warnings,
but the final fatal error becomes an Error exception. Combine
with @ to suppress FS warnings.

Closes GH-5641.
2020-06-05 09:46:39 +02:00
Rod Elias
682e2f6c20 Trim trailing whitespaces and fix code style
Closes GH-5554.
2020-05-12 17:00:11 +02:00
Máté Kocsis
4a816584a4
Make float to string casts locale-independent
From now on, float to string casting will always behave locale-independently.
RFC: https://wiki.php.net/rfc/locale_independent_float_to_string
Closes GH-5224

Co-authored-by: George Peter Banyard <girgias@php.net>
2020-05-08 10:52:23 +02:00
Nikita Popov
ef72b8f4ac Merge branch 'PHP-7.4'
* PHP-7.4:
  Make 045.phpt busy wait
2020-04-29 10:14:35 +02:00
Nikita Popov
b1b98e08d0 Make 045.phpt busy wait
The timeout is only real-time based on Windows. Make this use
a busy wait loop instead. If hard_timeout is broken, this will
fail with a run-tests enforced timeout instead.
2020-04-29 10:12:53 +02:00
Remi Collet
8e5df6092d fix test using short_tag 2020-04-15 09:26:55 +02:00
Alex Dowad
80598f1250 Syntax errors caused by unclosed {, [, ( mention specific location
Aside from a few very specific syntax errors for which detailed exceptions are
thrown, generally PHP just emits the default error messages generated by bison on syntax
error. These messages are very uninformative; they just say "Unexpected ... at line ...".

This is most problematic with constructs which can span an arbitrary number of lines, such
as blocks of code delimited by { }, 'if' conditions delimited by ( ), and so on. If a closing
delimiter is missed, the block will run for the entire remainder of the source file (which
could be thousands of lines), and then at the end, a parse error will be thrown with the
dreaded words: "Unexpected end of file".

Therefore, track the positions of opening and closing delimiters and ensure that they match
up correctly. If any mismatch or missing delimiter is detected, immediately throw a parse
error which points the user to the offending line. This is best done in the *lexer* and not
in the parser.

Thanks to Nikita Popov and George Peter Banyard for suggesting improvements.

Fixes bug #79368.
Closes GH-5364.
2020-04-14 11:22:23 +02:00
George Peter Banyard
55a3e5b99e Promote some warnings to Errors in Zend basic functions
Closes GH-5325
2020-03-31 16:32:58 +02:00
Máté Kocsis
36935e42ea
Improve undefined variable error messages
Closes GH-5312
2020-03-31 13:02:32 +02:00
Máté Kocsis
f44dd16b7a
Improve error message of foreach
Closes GH-5240
2020-03-09 11:29:40 +01:00
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Nikita Popov
a939805641 Use serialize_precision for var_dump()
var_dump() is debugging functionality, so it should print
floating-point numbers accurately. We do this by switching
to serialize_precision, which (by default) will print with
as much precision as necessary to preserve the exact value
of the float.

This also affects debug_zval_dump().

Closes GH-5172.
2020-02-25 09:51:32 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Dmitry Stogov
64b40f69dc Make ASSIGN, ASSIGN_OP, INC and DEC opcodes to return IS_TMP_VAR instead of IS_VAR.
This helps to avoid unnecessary IS_REFERENCE checks.
This changes some notices "Only variables should be passed by reference" to exception "Cannot pass parameter %d by reference".

Also, for consistency, compile-time fatal error "Only variables can be passed by reference" was converted to exception "Cannot pass parameter %d by reference"
2020-02-07 13:36:52 +03:00
Nikita Popov
f8d795820e Reindent phpt files 2020-02-03 22:52:20 +01:00
Máté Kocsis
d1764ca330
Make error messages more consistent by fixing capitalization
Closes GH-5066 As a first step, let's capitalize their initial letter when it is applicable.
2020-01-17 14:52:46 +01:00
Máté Kocsis
0b4778c377
Fix #78880: Another bunch of spelling errors 2020-01-16 09:46:47 +01:00
Nikita Popov
7ce531f2c2 Make constant() error handling consistent with plain const lookup
This means we get an Error exception and a much better error
message indicating the root cause (e.g. accessing a private class
constant).
2020-01-10 13:39:56 +01:00
George Peter Banyard
bfe3f934a3 Add warning and convert to exception in string offset assignment:
Convert the empty string assignment to an Error as per RFC [1]
Add a warning that only the first byte will be assigned to the offset if provided
a needle that is longer than one byte.

[1] https://wiki.php.net/rfc/engine_warnings
2020-01-07 21:54:42 +01:00