diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index a08a37ec98e0b..da984b946c900 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -105,7 +105,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp return 'null'; case is_object($value): if ($objectSupport) { - return '!!php/object:'.serialize($value); + return '!php/object:'.serialize($value); } if ($exceptionOnInvalidType) { @@ -477,8 +477,11 @@ private static function evaluateScalar($scalar, $references = array()) case 0 === strpos($scalar, '! '): return (int) self::parseScalar(substr($scalar, 2)); case 0 === strpos($scalar, '!!php/object:'): + @trigger_error('!!php/object is deprecated since version 3.0 and will be removed in 4.0. Use !php/object instead.', E_USER_DEPRECATED); + $scalar = substr($scalar, 1); + case 0 === strpos($scalar, '!php/object:'): if (self::$objectSupport) { - return unserialize(substr($scalar, 13)); + return unserialize(substr($scalar, 12)); } if (self::$exceptionOnInvalidType) { diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index b103b9a1844ce..4f29a51eaa9d7 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -180,7 +180,7 @@ public function testObjectSupportEnabled() { $dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true); - $this->assertEquals('{ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects'); + $this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects'); } public function testObjectSupportDisabledButNoExceptions() diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 7a861bf7ab629..131f8ca938abd 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -422,7 +422,7 @@ public function testBlockLiteralWithLeadingNewlines() public function testObjectSupportEnabled() { $input = <<assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects'); @@ -431,7 +431,7 @@ public function testObjectSupportEnabled() public function testObjectSupportDisabledButNoExceptions() { $input = <<parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false); + $this->parser->parse('foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false); + } + + public function testDeprecatedObjectNotation() + { + $input = <<parser->parse($input, true, true); + + $lastError = error_get_last(); + unset($lastError['file'], $lastError['line']); + + $xError = array( + 'type' => E_USER_DEPRECATED, + 'message' => '!!php/object is deprecated since version 3.0 and will be removed in 4.0. Use !php/object instead.', + ); + + $this->assertEquals(array('foo' => new B(), 'bar' => 1), $actual, '->parse() is able to parse objects'); + $this->assertSame($xError, $lastError); } /**