method canBeSerialized implemented #3

Open
wants to merge 4 commits into
from

Projects

None yet

3 participants

@tael
tael commented Feb 25, 2015

implements properly!

i'm not sure about write the test-code with phpUnit,
please someone improves that.

and i have no idea for 100 over recursive calls :(

  • it means class or array have 100 over depth. (really rarely)
@tael
tael commented Feb 25, 2015

related c217a59

@tael
tael commented Feb 25, 2015

i don't know that why DOMDocument can not be serialize...
DOMDocument::loadXML(): Empty string supplied as input

@whatthejeff
Collaborator

@tael Internal classes and classes extending internal classes can not be considered serializable if they do not implement the Serializable interface.

@tael
tael commented Feb 25, 2015

@whatthejeff
yea, i realized something is wrong :(
could you leave the link about 'Internal classes' ?
I think that I'm missing something conceptional.

@tael
tael commented Feb 25, 2015

@whatthejeff
oh, thanks !
I did not understood your code, and try to fix something.
what a foolish..
I will try fix more. thank you!

@tael
tael commented Feb 28, 2015

can someone check this PR? with any comment to improve :-)

@mrclay mrclay commented on the diff Oct 11, 2015
src/Snapshot.php
*/
private function canBeSerialized($variable)
{
- if (!is_object($variable)) {
- return !is_resource($variable);
+ if (is_object($variable)) {
+ if (!$this->canBeSerializedClass($variable)) {
+ return false;
+ }
+ $o = new \ReflectionObject($variable);
+ $properties = $o->getProperties(\ReflectionProperty::IS_STATIC | \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
+ foreach ($properties as $p) {
@mrclay
mrclay Oct 11, 2015 Contributor

Will this traverse dynamically added properties?

@mrclay mrclay commented on the diff Oct 11, 2015
src/Snapshot.php
*/
private function canBeSerialized($variable)
{
- if (!is_object($variable)) {
@mrclay
mrclay Oct 11, 2015 Contributor

Instead of truly catching circular references it might be sufficient to increment a counter in each nested canBeSerialized() call and return true once it's over, say, 50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment