8000 update php/object tag syntax by koenpunt · Pull Request #16952 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

update php/object tag syntax #16952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
update php/object tag syntax
the old syntax (double exclamation mark) is to represent native YAML
types, a single exclamation mark represent a local tag.
an E_USER_DEPRECATED error is triggered for old tags.
fixes #16877
  • Loading branch information
koenpunt committed Dec 10, 2015
commit 706aaaa860480415c9da24935143a88170ba33fb
7 changes: 5 additions & 2 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 use !php/object instead', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing silencing (which makes the testsuite fail btw)

$scalar = substr($scalar, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a comment saying the fallthrough is intended

case 0 === strpos($scalar, '!php/object:'):
if (self::$objectSupport) {
return unserialize(substr($scalar, 13));
return unserialize(substr($scalar, 12));
}

if (self::$exceptionOnInvalidType) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 24 additions & 2 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function testBlockLiteralWithLeadingNewlines()
public function testObjectSupportEnabled()
{
$input = <<<EOF
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
Expand All @@ -431,7 +431,7 @@ public function testObjectSupportEnabled()
public function testObjectSupportDisabledButNoExceptions()
{
$input = <<<EOF
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;

Expand All @@ -442,10 +442,32 @@ public function testObjectSupportDisabledButNoExceptions()
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testObjectsSupportDisabledWithExceptions()
{
$this->parser->parse('foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
}

/**
* @expectedException PHPUnit_Framework_Exception
* @expectedExceptionMessage !!php/object is deprecated use !php/object instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong. There is no exception with such message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPUnit converts errors to exceptions, so this exception actually is thrown.
Or isn't that what you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
public function testDeprecatedObjectNotation()
{
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
}

public function testDeprecatedObjectNotationWithErrorsSuppressed()
{
$input = <<<EOF
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;

$previous = error_reporting(E_ALL & ~E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not how we handle deprecations (because you miss the silencing)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how do we?

$actual = $this->parser->parse($input, false, true);
error_reporting($previous);
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $actual, '->parse() is able to parse objects');
}

/**
* @requires extension iconv
*/
Expand Down
0