Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
Serializing default property values is not required
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Jun 13, 2014
1 parent 5554094 commit dcba7c6
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions src/Instantiator/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ function () use ($reflectionClass) {
$serializationFormat = 'C';
}

$defaultValues = $this->getSerializedDefaultValues($reflectionClass);

$serializedString = sprintf(
'%s:%d:"%s":%s:{%s}',
'%s:%d:"%s":0:{}',
$serializationFormat,
strlen($className),
$className,
count($defaultValues),
implode('', $defaultValues)
$className
);

return $this->storeAndExecuteInstantiator(
Expand Down Expand Up @@ -116,37 +112,4 @@ private function hasInternalAncestors(ReflectionClass $reflectionClass)

return false;
}

/**
* @param ReflectionClass $reflectionClass
*
* @return string[]
*/
private function getSerializedDefaultValues(ReflectionClass $reflectionClass)
{
$properties = array();
$defaults = $reflectionClass->getDefaultProperties();

do {
foreach ($reflectionClass->getProperties() as $property) {
if (! $property->getDeclaringClass()->getName() === $reflectionClass->getName()) {
continue;
}

$visibility = 'public';

if ($property->isPrivate()) {
$visibility = "\0" . $property->getDeclaringClass()->getName() . "\0private";
}

if ($property->isProtected()) {
$visibility = "\0*\0protected";
}

$properties[] = serialize($visibility) . serialize($defaults[$property->getName()]);
}
} while ($reflectionClass = $reflectionClass->getParentClass());

return $properties;
}
}

0 comments on commit dcba7c6

Please sign in to comment.