Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ PHP NEWS

- Core:
. Implemented partial function application RFC. (Arnaud)
. Fixed bug GH-22263 (reset typed property default on every unserialize
failure path). (David Carlier)

- DOM:
. Fixed bug GH-22825 (DOMElement::setAttribute() fails silently when the DTD
declares a default value for the attribute). (iliaal)

- GMP:
. Fixed GMP power and shift operators to reject GMP right operands outside
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ PHP 8.6 UPGRADE NOTES
1. Backward Incompatible Changes
========================================

- Core:
. ??/empty() on a magic property no longer call __get() when __isset()
has materialised the property by writing into the property table.
The freshly-written value is returned directly. isset() is unaffected.

- COM
. It is no longer possible to clone variant objects, this is because
the cloning behaviour was ill defined.
Expand Down Expand Up @@ -566,6 +571,8 @@ PHP 8.6 UPGRADE NOTES
- Core:
. In case of a hard OOM PHP now calls abort() instead of exit(1), changing
the exit code to 134 and possibly creating a core dump.
. The PHP_OS_FAMILY constant has an AIX value for when running on AIX or
IBM i via PASE.

========================================
14. Performance Improvements
Expand Down
65 changes: 65 additions & 0 deletions Zend/tests/magic_methods/gh12695.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--TEST--
GH-12695: ?? on unset property does not call __get() when __isset() materialized the property
--FILE--
<?php

#[AllowDynamicProperties]
class A {
public function __get($n) {
throw new Exception("__get must not be called when __isset materialised the property");
}
public function __isset($n) {
echo " __isset($n)\n";
$this->$n = 123;
return true;
}
}

echo "Dynamic property materialised in __isset, then `??`:\n";
$a = new A;
var_dump($a->foo ?? 'fallback');

echo "\nSame on a declared (unset) property:\n";
class B {
public int $x = 99;
public function __get($n) {
throw new Exception("__get must not be called when __isset materialised the property");
}
public function __isset($n) {
echo " __isset($n)\n";
$this->$n = 7;
return true;
}
}
$b = new B;
unset($b->x);
var_dump($b->x ?? 'fallback');

echo "\nWhen __isset() materialises the property to null, `??` falls back:\n";
#[AllowDynamicProperties]
class D {
public function __get($n) {
throw new Exception("__get must not be called when __isset materialised the property");
}
public function __isset($n) {
echo " __isset($n)\n";
$this->$n = null;
return true;
}
}
$d = new D;
var_dump($d->foo ?? 'fallback');

?>
--EXPECT--
Dynamic property materialised in __isset, then `??`:
__isset(foo)
int(123)

Same on a declared (unset) property:
__isset(x)
int(7)

When __isset() materialises the property to null, `??` falls back:
__isset(foo)
string(8) "fallback"
55 changes: 55 additions & 0 deletions Zend/tests/magic_methods/gh12695_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
GH-12695: empty() on unset property does not call __get() when __isset() materialized the property
--FILE--
<?php

#[AllowDynamicProperties]
class A {
public function __get($n) {
throw new Exception("__get must not be called when __isset materialised the property");
}
public function __isset($n) {
echo " __isset($n)\n";
$this->$n = $GLOBALS['next_value'];
return true;
}
}

echo "empty() when __isset materialised a truthy value: __get is not called, empty=false:\n";
$GLOBALS['next_value'] = 7;
$a = new A;
var_dump(empty($a->foo));

echo "\nempty() when __isset materialised a falsy value: __get is not called, empty=true:\n";
$GLOBALS['next_value'] = 0;
$a = new A;
var_dump(empty($a->bar));

echo "\nempty() with no materialization: __get is still called (legacy path preserved):\n";
class B {
public function __get($n) {
echo " __get($n)\n";
return 'value';
}
public function __isset($n) {
echo " __isset($n)\n";
return true;
}
}
$b = new B;
var_dump(empty($b->any));

?>
--EXPECT--
empty() when __isset materialised a truthy value: __get is not called, empty=false:
__isset(foo)
bool(false)

empty() when __isset materialised a falsy value: __get is not called, empty=true:
__isset(bar)
bool(true)

empty() with no materialization: __get is still called (legacy path preserved):
__isset(any)
__get(any)
bool(false)
65 changes: 65 additions & 0 deletions Zend/tests/magic_methods/gh12695_no_materialization.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--TEST--
GH-12695: __get() invocation is based on __isset()'s return value
--FILE--
<?php

/* The re-check after __isset() must not affect the legacy path when
* the property is genuinely magic-only: __get() is still called and
* its return value drives `??`'s null check. */

echo "`??` when __isset=true and __get returns a value: __get is called:\n";
class C {
public function __get($n) {
echo " __get($n)\n";
return 'from-get';
}
public function __isset($n) {
echo " __isset($n)\n";
return true;
}
}
$c = new C;
var_dump($c->any ?? 'fallback');

echo "\n`??` when __isset=true and __get returns null: __get is called and fallback is used:\n";
class D {
public function __get($n) {
echo " __get($n)\n";
return null;
}
public function __isset($n) {
echo " __isset($n)\n";
return true;
}
}
$d = new D;
var_dump($d->any ?? 'fallback');

echo "\n`??` when __isset returns false: __get is not called:\n";
class E {
public function __get($n) {
throw new Exception("__get must not be called when __isset returned false");
}
public function __isset($n) {
echo " __isset($n)\n";
return false;
}
}
$e = new E;
var_dump($e->any ?? 'fallback');

?>
--EXPECT--
`??` when __isset=true and __get returns a value: __get is called:
__isset(any)
__get(any)
string(8) "from-get"

`??` when __isset=true and __get returns null: __get is called and fallback is used:
__isset(any)
__get(any)
string(8) "fallback"

`??` when __isset returns false: __get is not called:
__isset(any)
string(8) "fallback"
28 changes: 28 additions & 0 deletions Zend/tests/magic_methods/gh12695_object_released_in_isset.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-12695: Object freed by __isset() during materialization
--FILE--
<?php

/* The re-check after __isset() copies the materialised value into the
* caller's return-value buffer before releasing the object. This is
* required because __isset() may drop the last external reference to
* the object (here via $obj = null), so the property table is freed
* by OBJ_RELEASE() right after the re-check. */

class C {
public $prop;
public function __isset($name) {
global $obj;
$obj = null;
$this->prop = 'materialised';
return true;
}
}

$obj = new C();
unset($obj->prop);
var_dump($obj->prop ?? 'fb');

?>
--EXPECT--
string(12) "materialised"
116 changes: 116 additions & 0 deletions Zend/tests/partial_application/default_const_expr.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
--TEST--
PFA: constant-expression default for a skipped optional parameter
--FILE--
<?php

namespace App;

const K = 7;

function f($a, $b = K, $c = 0) {
return [$a, $b, $c];
}

function variadic($a, $b = K, $c = 0, ...$args) {
return [$a, $b, $c, $args];
}

function late($a, $b = LATE, $c = 0) {
return [$a, $b, $c];
}

function fallback($a, $b = GLOBAL_ONLY, $c = 0) {
return [$a, $b, $c];
}

class C {
const X = 42;
static function m($a, $b = self::X, $c = 0) {
return [$a, $b, $c];
}
}

enum E {
case A;
case B;
}

function g($a, $b = E::A, $c = 0) {
return [$a, $b->name, $c];
}

$p = f(a: 10, c: ?);
var_dump($p(99));

$v = variadic(a: 10, c: ?, foo: 1);
var_dump($v(99));

$q = C::m(a: 1, c: ?);
var_dump($q(9));

$r = g(a: 1, c: ?);
var_dump($r(9));

$l = late(a: 1, c: ?);
define('App\LATE', 'defined after the partial was created');
var_dump($l(9));

define('GLOBAL_ONLY', 'global fallback');
$s = fallback(a: 1, c: ?);
var_dump($s(9));

?>
--EXPECT--
array(3) {
[0]=>
int(10)
[1]=>
int(7)
[2]=>
int(99)
}
array(4) {
[0]=>
int(10)
[1]=>
int(7)
[2]=>
int(99)
[3]=>
array(1) {
["foo"]=>
int(1)
}
}
array(3) {
[0]=>
int(1)
[1]=>
int(42)
[2]=>
int(9)
}
array(3) {
[0]=>
int(1)
[1]=>
string(1) "A"
[2]=>
int(9)
}
array(3) {
[0]=>
int(1)
[1]=>
string(37) "defined after the partial was created"
[2]=>
int(9)
}
array(3) {
[0]=>
int(1)
[1]=>
string(15) "global fallback"
[2]=>
int(9)
}
Loading