PHP 8.1: Pspell Extension: pspell, pspell config resources are \PSpell, \PSpellConfig class objects

Version8.1
TypeChange

All resource types from Pspell extension are migrated to opaque class objects in PHP 8.1.

Prior to PHP 8.1, Pspell extension used resource object types pspell and pspell config with an integer identifier. These two identifier values are replaced with class objects named PSpell and PSpellConfig.

All functions that previously returned and accepted resource integer identifiers now accept their corresponding class objects.

Resource to Object Migration
PHP is gradually phasing out all resource types with class objects, and this migration is one step of the Resource to Object Migration plan.

PSpell Class

PSpell class replaces the resource objects of type pspell. PHP returned an int identifier for this prior to PHP 8.1, and returns a PSpell class object in PHP 8.1 and later instead.

final class PSpell {}

All functions that returned or accepted pspell object identifiers are changed to return/accept new PSpell class objects.

The following functions are used to instantiate PSpell objects. They previously returned pspell resource identifiers as integers.

The following functions accepted pspell resource object identifiers, and are changed to accept PSpell class objects instead:

Instantiating a PSpell object with new PSpell construct is not allowed:

new PSpell();
PHP Error:  You cannot initialize a PSpell object except through helper functions in ... code on line ...

It is not allowed to serialize a PSpell object either:

serialize(pspell_new("en", "", "", ""));
Serialization of 'PSpell' is not allowed

PSpellConfig Class

The new PSpellConfig class replaces pspell config resource object identifiers (int values).

final class PSpellConfig {}

Similar to all other resource to class object migrations, all functions that returned/accepted pspell config resource object identifiers now accept PSpellConfig class instances.

  • pspell_config_create() function previously returned and int identifier for pspell config resource objects, but return PSpellConfig class instances instead in PHP 8.1 and later.

  • pspell_new_config() function previously accepted pspell config resource objects identifiers as int, and are changed to accept PSpellConfig class objects from PHP 8.1 and later.

It is not allowed to use new PSpellConfig construct to instantiate a PSpellConfig instance.

new PSpellConfig();
PHP Error:  You cannot initialize a PSpellConfig object except through helper functions in ... code on line ...

Further, it is not allowed to serialize a PSpell object either.

serialize(pspell_config_create('en'));
Serialization of 'PSpellConfig' is not allowed

Destroying PSpell resources

Prior to PHP 8.1, there were no specific functions to forcefully close a pspell/pspell config resource. PHP automatically cleans them with garbage cleaning.

From PHP 8.1 and later, the returned PSpell/PSpellConfig objects follow general object garbage-cleaning mechanisms, and they will be cleared when the objects fall out of scope. It is possible to explicitly destroy an object with unset() construct too.

Backwards Compatibility Impact

Prior to PHP 8.1, all pspell_* functions returned/accepted resource objects as integer identifiers. They are now changed in PHP 8.1 and later to return class objects instead.

Failure to instantiate any object return false, and this pattern is not changed in PHP 8.1.

It was possible to serialize the return values from pspell_* functions, erroneously so, prior to PHP 8.1, but the new class objects are not allowed to be serialized.


Implementation