PHP Basics

Changelog

v3.0.1

Bug Fixes:

  • Removed @psalm-consistent-templates from StrictCollection , StrictList , StrictQueue and StrictStack , because it made Psalm reject subclasses with a fixed item type (e.g. class MyQueue extends StrictQueue<Foo> )

v3.0.0

New Features:

  • Added a PHPUnit test suite (composer phpunit:test ), running on PHP 8.2 to 8.5 in CI
  • Added static fromArray() constructors to all datastructures (e.g. StrictList::fromArray([1, 2], ['int']) ), which also let PHPStan and Psalm infer the item types
  • TypeChecker (and thus all datastructures) now supports union types (e.g. int|string ), nullable types (e.g. ?int ) and mixed

Breaking Changes:

  • Raised minimum PHP version from 8.1 to 8.2, as PHP 8.1 reached end of life
  • Atomic type keywords for TypeChecker (and thus all datastructures) are now case-sensitive and must be lowercase (e.g. 'Int' or 'STRING' are now treated as class names and therefore never match scalar values)
  • StrictCollection and StrictArray no longer implement the legacy Serializable interface (and thus no longer have serialize() and unserialize() methods). Serializing them with PHP's serialize() and unserialize() functions works as before. StrictList , StrictQueue and StrictStack still implement it, because their SPL parent classes do
  • Getter::__isset() no longer swallows exceptions thrown by _magicGet*() methods
  • TypeChecker::setAllowedTypes() splits union and nullable types into separate types and throws an InvalidArgumentException for empty types (e.g. '' or 'int|' )

Maintenance:

  • Updated Psalm to version 7 and PHP Mess Detector to version 3
  • Imported the Override and ReturnTypeWillChange attributes instead of using their fully qualified names
  • The documentation is now built and deployed by GitHub Actions on every new release instead of being committed to the repository

Bug Fixes:

  • TypeChecker no longer calls arbitrary is_*() functions for class names (e.g. a class File caused a TypeError from is_file() , and Countable accepted arrays via is_countable() ). Everything but the atomic type keywords is now checked with instanceof
  • StrictArray now supports appending with $array[] = $value
  • StrictCollection::get() and StrictCollection::remove() now work for items with value null
  • TriggerExceptionError no longer uses E_USER_ERROR (deprecated since PHP 8.4), but triggers an E_USER_WARNING and exits with status 255
  • StrictList::add() , StrictQueue::add() and StrictStack::add() now insert the item at the given offset instead of replacing the existing item
  • StrictList::prepend() , StrictQueue::prepend() and StrictStack::prepend() now keep the order of the given items (like array_unshift() ) instead of reversing them
  • Unserializing a StrictStack (or any list in LIFO iteration mode) no longer reverses the order of its items

v2.1.3

Maintenance:

  • Updated development dependencies
  • Raised PHPStan rule level to 10
  • Updated links to documentation
  • Used more generics in PHPStan and Psalm type-hints

v2.1.2

New Features:

  • Added Composer commands for development tools (PHP Mess Detector, Psalm Taint Analysis)

v2.1.1

New Features:

  • Added Composer commands for development tools (PHP_CodeSniffer, PHP-CS-Fixer, PHPStan, Psalm and phpDocumentor)

Minor Changes:

v2.1.0

Breaking Changes:

New Features:

v2.0.0

Breaking Changes:

  • Raised minimum PHP version from 8.0 to 8.1 in order to use new features like array_is_list() and the spread operator on string-keyed arrays
  • Interfaces traits renamed and moved to different namespace

    OCC\Basics\InterfaceTraits\ArrayAccess       -> OCC\Basics\Interfaces\ArrayAccessTrait
    OCC\Basics\InterfaceTraits\Countable         -> OCC\Basics\Interfaces\CountableTrait
    OCC\Basics\InterfaceTraits\IteratorAggregate -> OCC\Basics\Interfaces\IteratorAggregateTrait
    OCC\Basics\InterfaceTraits\Iterator          -> OCC\Basics\Interfaces\IteratorTrait
  • Prefixed internal methods for Getter and Setter with _ to avoid confusion with regular class methods

    // old methods
    function magicGet{Property}(): mixed
    function magicSet{Property}(mixed $value): void
    // new methods
    function _magicGet{Property}(): mixed
    function _magicSet{Property}(mixed $value): void

New Features:

Minor Changes:

v1.1.0

Breaking Changes:

  • Changed the constructor's signature for all DataStructures to improve compatibility with the corresponding SPL datastructures

    // old constructor signature
    public function __construct(iterable $items = [], array $allowedTypes = [])
    // new constructor signature
    public function __construct(array $allowedTypes = [])

v1.0.1

Minor Changes:

  • Improved exception handling in Singleton trait

v1.0.0

Initial Release

Search results