-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
update php/object tag syntax #16952
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 use !php/object instead', E_USER_DEPRECATED); | ||
$scalar = substr($scalar, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
|
@@ -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; | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong. There is no exception with such message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHPUnit converts errors to exceptions, so this exception actually is thrown. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not how we handle deprecations (because you miss the silencing) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
*/ | ||
|
There was a problem hiding this comment.
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)