Skip to content

Commit 26979ed

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Yaml] Fix tests on PHP 7.0.2 [2.7] Workaround https://bugs.php.net/63206 [2.3] Workaround https://bugs.php.net/63206 Add closing parenthesis [Serializer] Unset object_to_populate after using it [Serializer] Allow to use proxies in object_to_populate
2 parents c60053e + 3c6d1a9 commit 26979ed

File tree

12 files changed

+99
-23
lines changed

12 files changed

+99
-23
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ErrorHandler
9595

9696
private $loggedTraces = array();
9797
private $isRecursive = 0;
98+
private $isRoot = false;
9899
private $exceptionHandler;
99100
private $bootstrappingLogger;
100101

@@ -136,7 +137,12 @@ public static function register($handler = null, $replace = true)
136137
$handler = new static();
137138
}
138139

139-
$prev = set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
140+
if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
141+
restore_error_handler();
142+
// Specifying the error types earlier would expose us to https://bugs.php.net/63206
143+
set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
144+
$handler->isRoot = true;
145+
}
140146

141147
if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
142148
$handler = $prev[0];
@@ -352,12 +358,16 @@ public function screamAt($levels, $replace = false)
352358
private function reRegister($prev)
353359
{
354360
if ($prev !== $this->thrownErrors | $this->loggedErrors) {
355-
$handler = set_error_handler('var_dump', 0);
361+
$handler = set_error_handler('var_dump');
356362
$handler = is_array($handler) ? $handler[0] : null;
357363
restore_error_handler();
358364
if ($handler === $this) {
359365
restore_error_handler();
360-
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
366+
if ($this->isRoot) {
367+
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
368+
} else {
369+
set_error_handler(array($this, 'handleError'));
370+
}
361371
}
362372
}
363373
}
@@ -597,7 +607,7 @@ public static function handleFatalError(array $error = null)
597607

598608
self::$reservedMemory = null;
599609

600-
$handler = set_error_handler('var_dump', 0);
610+
$handler = set_error_handler('var_dump');
601611
$handler = is_array($handler) ? $handler[0] : null;
602612
restore_error_handler();
603613

@@ -742,7 +752,7 @@ public static function setLogger(LoggerInterface $logger, $channel = 'deprecatio
742752
{
743753
@trigger_error('The '.__METHOD__.' static method is deprecated since version 2.6 and will be removed in 3.0. Use the setLoggers() or setDefaultLogger() methods instead.', E_USER_DEPRECATED);
744754

745-
$handler = set_error_handler('var_dump', 0);
755+
$handler = set_error_handler('var_dump');
746756
$handler = is_array($handler) ? $handler[0] : null;
747757
restore_error_handler();
748758
if (!$handler instanceof self) {

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testClassAlias()
175175
*/
176176
public function testDeprecatedSuper($class, $super, $type)
177177
{
178-
set_error_handler('var_dump', 0);
178+
set_error_handler(function() { return false; });
179179
$e = error_reporting(0);
180180
trigger_error('', E_USER_DEPRECATED);
181181

@@ -205,7 +205,7 @@ public function provideDeprecatedSuper()
205205

206206
public function testInterfaceExtendsDeprecatedInterface()
207207
{
208-
set_error_handler('var_dump', 0);
208+
set_error_handler(function() { return false; });
209209
$e = error_reporting(0);
210210
trigger_error('', E_USER_NOTICE);
211211

@@ -227,7 +227,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true);
227227

228228
public function testDeprecatedSuperInSameNamespace()
229229
{
230-
set_error_handler('var_dump', 0);
230+
set_error_handler(function() { return false; });
231231
$e = error_reporting(0);
232232
trigger_error('', E_USER_NOTICE);
233233

@@ -253,7 +253,7 @@ public function testReservedForPhp7()
253253
$this->markTestSkipped('PHP7 already prevents using reserved names.');
254254
}
255255

256-
set_error_handler('var_dump', 0);
256+
set_error_handler(function() { return false; });
257257
$e = error_reporting(0);
258258
trigger_error('', E_USER_NOTICE);
259259

src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface EventSubscriberInterface
3838
*
3939
* * array('eventName' => 'methodName')
4040
* * array('eventName' => array('methodName', $priority))
41-
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
41+
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
4242
*
4343
* @return array The event names to listen to
4444
*/

src/Symfony/Component/Filesystem/LockHandler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ public function lock($blocking = false)
6868
return true;
6969
}
7070

71-
// Silence both userland and native PHP error handlers
72-
$errorLevel = error_reporting(0);
73-
set_error_handler('var_dump', 0);
71+
// Silence error reporting
72+
set_error_handler(function() {});
7473

7574
if (!$this->handle = fopen($this->file, 'r')) {
7675
if ($this->handle = fopen($this->file, 'x')) {
@@ -81,7 +80,6 @@ public function lock($blocking = false)
8180
}
8281
}
8382
restore_error_handler();
84-
error_reporting($errorLevel);
8583

8684
if (!$this->handle) {
8785
$error = error_get_last();

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function setData($data = array())
106106
// PHP 5.3 triggers annoying warnings for some
107107
// types that can't be serialized as JSON (INF, resources, etc.)
108108
// but doesn't provide the JsonSerializable interface.
109-
set_error_handler('var_dump', 0);
109+
set_error_handler(function () { return false; });
110110
$data = @json_encode($data, $this->encodingOptions);
111111
} else {
112112
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function configure(Event $event = null)
6767
}
6868
$this->firstCall = false;
6969
if ($this->logger || null !== $this->throwAt) {
70-
$handler = set_error_handler('var_dump', 0);
70+
$handler = set_error_handler('var_dump');
7171
$handler = is_array($handler) ? $handler[0] : null;
7272
restore_error_handler();
7373
if ($handler instanceof ErrorHandler) {

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ protected function prepareForDenormalization($data)
279279
* Instantiates an object using constructor parameters when needed.
280280
*
281281
* This method also allows to denormalize data into an existing object if
282-
* it is present in the context with the object_to_populate key.
282+
* it is present in the context with the object_to_populate. This object
283+
* is removed from the context before being returned to avoid side effects
284+
* when recursively normalizing an object graph.
283285
*
284286
* @param array $data
285287
* @param string $class
@@ -296,9 +298,12 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
296298
if (
297299
isset($context['object_to_populate']) &&
298300
is_object($context['object_to_populate']) &&
299-
$class === get_class($context['object_to_populate'])
301+
$context['object_to_populate'] instanceof $class
300302
) {
301-
return $context['object_to_populate'];
303+
$object = $context['object_to_populate'];
304+
unset($context['object_to_populate']);
305+
306+
return $object;
302307
}
303308

304309
$constructor = $reflectionClass->getConstructor();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Kévin Dunglas <[email protected]>
16+
*/
17+
class ProxyDummy extends ToBeProxyfiedDummy
18+
{
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Kévin Dunglas <[email protected]>
16+
*/
17+
class ToBeProxyfiedDummy
18+
{
19+
private $foo;
20+
21+
public function setFoo($foo)
22+
{
23+
$this->foo = $foo;
24+
}
25+
26+
public function getFoo()
27+
{
28+
return $this->foo;
29+
}
30+
}

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
66
use Symfony\Component\Serializer\Mapping\ClassMetadata;
77
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
8+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
89
use Symfony\Component\Serializer\Tests\Fixtures\AbstractNormalizerDummy;
10+
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;
911

1012
/**
1113
* Provides a dummy Normalizer which extends the AbstractNormalizer.
@@ -88,4 +90,16 @@ public function testGetAllowedAttributesAsObjects()
8890
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('other')), false);
8991
$this->assertEquals(array($a3, $a4), $result);
9092
}
93+
94+
public function testObjectToPopulateWithProxy()
95+
{
96+
$proxyDummy = new ProxyDummy();
97+
98+
$context = array('object_to_populate' => $proxyDummy);
99+
100+
$normalizer = new ObjectNormalizer();
101+
$normalizer->denormalize(array('foo' => 'bar'), 'Symfony\Component\Serializer\Tests\Fixtures\ToBeProxyfiedDummy', null, $context);
102+
103+
$this->assertSame('bar', $proxyDummy->getFoo());
104+
}
91105
}

0 commit comments

Comments
 (0)