PHP 8.1: Pspell: pspell, pspell config resources are PSpell\Dictionary, PSpell\Config class objects


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\Dictionary and PSpell\Config.

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

PSpell\Dictionary 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.

namespace PSpell;
final class Dictionary {}

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

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

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

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

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

It is not allowed to serialize a PSpell\Dictionary object either:

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

PSpell\Config Class

The new PSpell\Config class replaces pspell config resource object identifiers (int values).

namespace PSpell;
final class Config {}

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

  • pspell_config_create() function previously returned and int identifier for pspell config resource objects, but return PSpell\Config 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 PSpell\Config class objects from PHP 8.1 and later.

It is not allowed to use new PSpell\Config construct to instantiate a PSpell\Config instance.

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

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

Serialization of 'PSpell\Config' 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\Dictionary/PSpell\Config 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.