The NonSerializableTrait prevents object serialization via php's native serialization mechanism. Most objects are not safe to serialize, and NonSerializableTrait provides a covenient and uniform way to protect against serialization attempts. This patch applies the NonSerializableTrait to some key classes in MediaWiki. Bug: T187731 Bug: T259181 Change-Id: I0c3b558d97e3415413bbaa3d98f6ebd5312c4a67
19 lines
357 B
PHP
19 lines
357 B
PHP
<?php
|
|
|
|
namespace Wikimedia\NonSerializable;
|
|
|
|
use LogicException;
|
|
|
|
/**
|
|
* A trait that prevents serialization via php's builtin serialize() function.
|
|
*/
|
|
trait NonSerializableTrait {
|
|
|
|
/**
|
|
* @throws LogicException always
|
|
*/
|
|
public function __sleep() {
|
|
throw new LogicException( 'Instances of ' . get_class( $this ) . ' are not serializable!' );
|
|
}
|
|
|
|
}
|