Skip to content
Snippets Groups Projects
Commit 5c870439 authored by David Prévot's avatar David Prévot
Browse files

Merge tag '2.5.1' into upstream

Total issues resolved: **2**

- [536: Accessing properties of Serializable proxy](https://github.com/Ocramius/ProxyManager/issues/536) thanks to @Ludo444
- [537: Use ReflectionClass to create proxied class instance inside PublicScopeSimulator](https://github.com/Ocramius/ProxyManager/pull/537) thanks to @Ludo444

# gpg: Signature faite le mar. 17 déc. 2019 20:24:07 AEDT
# gpg:                avec la clef RSA 969287AB0A84CAAE3F48A69C4167D3337FD9D629
# gpg: Bonne signature de « Marco Pivetta (Ocramius) <ocramius@gmail.com> » [inconnu]
# gpg:                 alias « [jpeg image of size 3228] » [inconnu]
# gpg:                 alias « [jpeg image of size 12261] » [inconnu]
# gpg: Attention : cette clef n'est pas certifiée avec une signature de confiance.
# gpg:             Rien n'indique que la signature appartient à son propriétaire.
# Empreinte de clef principale : 7BB9 B50F E8E0 2118 7914  A5C0 9F65 FBC2 12EC 2DF8
#    Empreinte de la sous-clef : 9692 87AB 0A84 CAAE 3F48  A69C 4167 D333 7FD9 D629
parents 08a4b7a9 b7bac968
No related branches found
No related tags found
No related merge requests found
Showing
with 246 additions and 6 deletions
......@@ -112,7 +112,7 @@ class PublicScopeSimulator
return '$this->' . $valueHolder->getName();
}
return 'unserialize(sprintf(\'O:%d:"%s":0:{}\', strlen(get_parent_class($this)), get_parent_class($this)))';
return '$realInstanceReflection->newInstanceWithoutConstructor()';
}
/**
......
......@@ -40,7 +40,7 @@ if (! $realInstanceReflection->hasProperty($foo)) {
return;
}
$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this)));
$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
$accessor = function & () use ($targetObject, $name) {
return $targetObject->$foo;
};
......@@ -74,7 +74,7 @@ if (! $realInstanceReflection->hasProperty($foo)) {
return;
}
$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this)));
$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
$accessor = function & () use ($targetObject, $name, $value) {
return $targetObject->$foo = $baz;
};
......@@ -108,7 +108,7 @@ if (! $realInstanceReflection->hasProperty($foo)) {
return;
}
$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this)));
$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
$accessor = function () use ($targetObject, $name) {
return isset($targetObject->$foo);
};
......@@ -142,7 +142,7 @@ if (! $realInstanceReflection->hasProperty($foo)) {
return;
}
$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this)));
$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
$accessor = function () use ($targetObject, $name) {
unset($targetObject->$foo);
};
......@@ -241,7 +241,7 @@ if (! $realInstanceReflection->hasProperty($foo)) {
return;
}
$targetObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen(get_parent_class($this)), get_parent_class($this)));
$targetObject = $realInstanceReflection->newInstanceWithoutConstructor();
$accessor = function & () use ($targetObject, $name) {
return $targetObject->$foo;
};
......
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class private property direct isset check
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
private $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
var_dump(isset($proxy->sweets));
?>
--EXPECT--
bool(false)
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class private property direct read
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
private $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
$proxy->sweets;
?>
--EXPECTF--
%SFatal error:%sCannot access private property %s::$sweets in %a
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class private property direct unset
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
private $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
unset($proxy->sweets);
?>
--EXPECTF--
%SFatal error:%sCannot %s property%sin %a
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class private property direct write
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
private $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
$proxy->sweets = 'stolen';
?>
--EXPECTF--
%SFatal error:%sCannot %s property%sin %a
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class protected property direct isset check
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
protected $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
var_dump(isset($proxy->sweets));
?>
--EXPECT--
bool(false)
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class protected property direct read
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
protected $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
$proxy->sweets;
?>
--EXPECTF--
%SFatal error:%sCannot access protected property %s::$sweets in %a
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class protected property direct unset
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
protected $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
unset($proxy->sweets);
?>
--EXPECTF--
%SFatal error:%sCannot %s property%sin %a
--TEST--
Verifies that generated access interceptors doesn't throw PHP Warning on Serialized class protected property direct write
--FILE--
<?php
require_once __DIR__ . '/init.php';
class Kitchen implements \Serializable
{
protected $sweets = 'candy';
function serialize()
{
return $this->sweets;
}
function unserialize($serialized)
{
$this->sweets = $serialized;
}
}
$factory = new \ProxyManager\Factory\AccessInterceptorScopeLocalizerFactory($configuration);
$proxy = $factory->createProxy(new Kitchen());
$proxy->sweets = 'stolen';
?>
--EXPECTF--
%SFatal error:%sCannot %s property%sin %a
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment