Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[VarExporter] a new component to serialize values to plain PHP code#28231

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromnicolas-grekas:var-exporter
Aug 27, 2018

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 19, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

This PR proposes moving what is currently thePhpMarshaller class in the Cache component to a separate component.

This component would provide only one public static method:
VarExporter::export($value, bool &$isStaticValue = null): string.

This method returns$value serialized as plain PHP code. Running this code creates the same exact data structure that$value contained. This is exactly likeserialize() andunserialize(), from which all semantics are preserved (__sleep,__wakeup andSerializable).

The reason to use this methodvsserialize() or even igbinary is performance: thanks to OPcache, the resulting code is significantly faster and more memory efficient than usingunserialize() origbinary_unserialize().

Unlikevar_export(), this works on any serializable PHP value.

It also provides a few improvements overvar_export()/serialize():

  • the output is PSR-2 compatible
  • the output can be re-indented without messing up with any\r or\n in the data
  • missing classes throw aReflectionException instead of being unserialized to aPHP_Incomplete_Class object
  • references involvingSplObjectStorage,ArrayObject orArrayIterator instances are preserved
  • Reflection*,IteratorIterator andRecursiveIteratorIterator classes throw an exception when being serialized (their unserialized version is broken anyway, seehttps://bugs.php.net/76737.)

julienbourdeau, tolry, Axxon, rybakit, colinodell, ro0NL, prisis, regniblod, theofidry, emr, and romainnorberg reacted with thumbs up emojilinaori, hilobok, azjezz, Toflar, jepster, Kocal, fancyweb, welcoMattic, GuilhemN, soukicz, and 12 more reacted with hooray emoji
@tolry
Copy link

since the naming is similar/identical it might be a good idea to distinguish this from the php core functionhttp://php.net/manual/de/function.var-export.php ?

@nicolas-grekasnicolas-grekasforce-pushed thevar-exporter branch 2 times, most recently from6d05c08 to8668202CompareAugust 20, 2018 11:36
@nicolas-grekas
Copy link
MemberAuthor

@tolry we have theVarDumper component that provides a bettervar_dump() function. I think that theVarExporter name conveys what it should: this is a bettervar_export().

yceruto, colinodell, OskarStark, webnet-fr, and ismail1432 reacted with thumbs up emojiismail1432 reacted with laugh emojiismail1432 reacted with heart emojiismail1432 reacted with rocket emoji

@nicolas-grekasnicolas-grekasforce-pushed thevar-exporter branch 2 times, most recently from77d9f7a toe07f116CompareAugust 20, 2018 11:51
@tolry
Copy link

@nicolas-grekas I guessed so, just thought it might be easier to grasp, if the explanation mentioned var_export explicitely. Ah, I see it's in there now - did you add it or did I miss it before? 😁

@nicolas-grekasnicolas-grekasforce-pushed thevar-exporter branch 4 times, most recently from6114d8f to81606f9CompareAugust 20, 2018 13:55
@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedAug 20, 2018
edited
Loading

@tolry yes, I updated the description.

PR is ready IMHO.

Copy link
Contributor

@srozesroze left a comment

Choose a reason for hiding this comment

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

Except these two comments, it looks good to me 👌

Note that it's very likely it will require more maintenance than when it was internal.

useSymfony\Component\VarExporter\Internal\Values;

/**
* @author Nicolas Grekas <p@tchwork.com>
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually put that at the end of the comment.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

moved down

"name":"symfony/var-exporter",
"type":"library",
"description":"A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code",
"keywords": ["export","serialize"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd addsymfony andvar-exporter as well, they are the component 💃

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

this is already in the name of the component, no need to duplicate

4.2.0
-----

* added the component
Copy link
Contributor

Choose a reason for hiding this comment

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

-  * added the component+ * Created the component (extracted `PhpMarshaller` from the `Cache` component)

Could be valuable to give a hint of where it comes from.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

PhpMarshaller has never been released, better not give it any existence except in internal history
I'd keep as is :)

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedAug 24, 2018
edited
Loading

Note that it's very likely it will require more maintenance than when it was internal.

That's why I added more tests for more cases (and fixes) ;)

Comments addressed, thanks for the review.

=====================

The VarExporter component allows exporting any serializable PHP data structure to
plain PHP code. While doing so, it preserves all the semantics associated to the
Copy link
Member

Choose a reason for hiding this comment

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

associated with


The VarExporter component allows exporting any serializable PHP data structure to
plain PHP code. While doing so, it preserves all the semantics associated to the
serialization mechanism of PHP (`__wakeup`,`__sleep`,`Serializable` esp.)
Copy link
Member

Choose a reason for hiding this comment

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

"esp" can be removed IMHO

Unlike`var_export()`, this works on any serializable PHP value.

It also provides a few improvements over`var_export()`/`serialize()`:
* the output is PSR-2 compatible
Copy link
Member

Choose a reason for hiding this comment

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

missing empty line before the list, and missing; at the end of each line but the last.

instances are preserved
*`Reflection*`,`IteratorIterator` and`RecursiveIteratorIterator` classes
throw an exception when being serialized (their unserialized version is broken
anyway, seehttps://bugs.php.net/76737.)
Copy link
Member

Choose a reason for hiding this comment

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

dot outside the parenthesis

Copy link
Member

Choose a reason for hiding this comment

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

extra space after "see"

*PhpMarshaller allows serializing PHP data structuresusingvar_export()
* while preserving all the semantics associated to serialize().
*VarExporter allows serializing PHP data structuresto plain PHP code (likevar_export())
* while preserving all the semantics associated to serialize() (unlike var_export()).
Copy link
Member

Choose a reason for hiding this comment

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

associated with

*
* @return string The value exported as PHP code
*
* @throw \Exception When the provided value cannot be serialized
Copy link
Member

Choose a reason for hiding this comment

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

@nicolas-grekas
Copy link
MemberAuthor

Comments addressed thanks.

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit7831ad7 intosymfony:masterAug 27, 2018
fabpot added a commit that referenced this pull requestAug 27, 2018
…lain PHP code (nicolas-grekas)This PR was merged into the 4.2-dev branch.Discussion----------[VarExporter] a new component to serialize values to plain PHP code| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -This PR proposes moving what is currently the `PhpMarshaller` class in the Cache component to a separate component.This component would provide only one public static method:`VarExporter::export($value, bool &$isStaticValue = null): string`.This method returns `$value` serialized as plain PHP code. Running this code creates the same exact data structure that `$value` contained. This is exactly like `serialize()` and `unserialize()`, from which all semantics are preserved (`__sleep`, `__wakeup` and `Serializable`).The reason to use this method *vs* `serialize()` or even igbinary is performance: thanks to OPcache, the resulting code is significantly faster and more memory efficient than using `unserialize()` or `igbinary_unserialize()`.Unlike `var_export()`, this works on any serializable PHP value.It also provides a few improvements over `var_export()`/`serialize()`:- the output is PSR-2 compatible- the output can be re-indented without messing up with any `\r` or `\n` in the data- missing classes throw a `ReflectionException` instead of being unserialized to a `PHP_Incomplete_Class` object- references involving `SplObjectStorage`, `ArrayObject` or `ArrayIterator` instances are preserved- `Reflection*`, `IteratorIterator` and `RecursiveIteratorIterator` classes throw an exception when being serialized (their unserialized version is broken anyway, seehttps://bugs.php.net/76737.)Commits-------7831ad7 [VarExporter] a new component to serialize values to plain PHP code
@nicolas-grekasnicolas-grekas deleted the var-exporter branchAugust 30, 2018 15:24
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@srozesrozesroze approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

5 participants

@nicolas-grekas@tolry@fabpot@sroze@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp