Skip to content
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

Remove PHP 8.1 deprecated warnings #41

Merged
merged 3 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/coveralls-upload.json
/phpunit.xml
/vendor/
/.phpunit.result.cache
24 changes: 19 additions & 5 deletions src/Collector/AbstractCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Laminas\DeveloperTools\Collector;

use Serializable;

/**
* Serializable Collector base class.
*
*/
abstract class AbstractCollector implements CollectorInterface, \Serializable
abstract class AbstractCollector implements CollectorInterface, Serializable
{
/**
* Collected Data
Expand All @@ -15,19 +17,31 @@ abstract class AbstractCollector implements CollectorInterface, \Serializable
*/
protected $data;

public function __serialize()
{
return serialize($this->data);
}
Comment on lines +20 to +23
Copy link

@driehle driehle Dec 16, 2021

Choose a reason for hiding this comment

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

@snapshotpl Shouldn't this return an array instead of a serialized string? From https://www.php.net/manual/language.oop5.magic.php#object.serialize:

public __serialize(): array
public __unserialize(array $data): void

serialize() checks if the class has a function with the magic name __serialize(). If so, that function is executed prior to any serialization. It must construct and return an associative array of key/value pairs that represent the serialized form of the object. If no array is returned a TypeError will be thrown.

Copy link
Member

Choose a reason for hiding this comment

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

@driehle
Good catch! 👍
Please create an issue report or a pull request for this problem. Thanks in advance!


/**
* @see \Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function serialize()
{
return serialize($this->data);
return $this->__serialize();
}

public function __unserialize($data)
{
$this->data = unserialize($data);
}
Comment on lines +34 to 37
Copy link

Choose a reason for hiding this comment

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

See above, $data should be an array at this point, i.e. no need to call unserialize().


/**
* @see \Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function unserialize($data)
{
$this->data = unserialize($data);
$this->__unserialize($data);
}
}
24 changes: 18 additions & 6 deletions src/Collector/ConfigCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,36 @@ public function getApplicationConfig()
return isset($this->applicationConfig) ? $this->unserializeArray($this->applicationConfig) : null;
}

/**
* {@inheritDoc}
*/
public function serialize()
public function __serialize()
{
return serialize(['config' => $this->config, 'applicationConfig' => $this->applicationConfig]);
}

/**
* {@inheritDoc}
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function unserialize($serialized)
public function serialize()
{
return $this->__serialize();
}

public function __unserialize($serialized)
{
$data = unserialize($serialized);
$this->config = $data['config'];
$this->applicationConfig = $data['applicationConfig'];
}

/**
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function unserialize($serialized)
{
$this->__unserialize($serialized);
}

/**
* Replaces the un-serializable items in an array with stubs
*
Expand Down
20 changes: 16 additions & 4 deletions src/Collector/DbCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,31 @@ public function getQueryTime($mode = null)
return $time;
}

public function __serialize()
{
return serialize($this->profiler);
}

/**
* @see Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function serialize()
{
return serialize($this->profiler);
return $this->__serialize();
}

public function __unserialize($profiler)
{
$this->profiler = unserialize($profiler);
}

/**
* @see Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function unserialize($profiler)
{
$this->profiler = unserialize($profiler);
$this->__unserialize($profiler);
}
}
20 changes: 16 additions & 4 deletions src/Exception/SerializableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,31 @@ protected function filterArgs($args, $level = 0)
return $result;
}

public function __serialize()
{
return serialize($this->data);
}

/**
* @see \Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function serialize()
{
return serialize($this->data);
return $this->__serialize();
}

public function __unserialize($data)
{
$this->data = unserialize($data);
}

/**
* @see \Serializable
* @deprecated since 2.3.0, this method will be removed in version 3.0.0 of this component.
* {@see Serializable} as alternative
*/
public function unserialize($data)
{
$this->data = unserialize($data);
$this->__unserialize($data);
}
}