How To Start Using Generic Types In PHP

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • Psalm

    A static analysis tool for finding errors in PHP applications

  • root@2fde6041ad38:/app# vendor/bin/psalm public/test.php Target PHP version: 8.1 (inferred from current PHP version) Scanning files... Analyzing files... E ERROR: UndefinedPropertyFetch - public/test.php:29:1 - Instance property ServiceB::$serviceAProperty is not defined (see https://psalm.dev/039) $serviceLocator->getService(ServiceB::class)->serviceAProperty; ERROR: InvalidScalarArgument - public/test.php:88:28 - Argument 1 of CallbackExecutor::execute expects callable(int):string, pure-Closure(string):float provided (see https://psalm.dev/012) $callbackExecutor->execute(fn(string $value) => (float) $value, 1); ------------------------------ 2 errors found ------------------------------ 3 other issues found. You can display them with --show-info=true ------------------------------ Psalm can automatically fix 1 of these issues. Run Psalm again with --alter --issues=MissingReturnType --dry-run to see what it can fix. ------------------------------ Checks took 0.49 seconds and used 75.842MB of memory Psalm was able to infer types for 98.6486% of the codebase

  • PHPStan

    PHP Static Analysis Tool - discover bugs in your code without running it!

  • In theory, everything looks nice. There is only one small problem - PHP does not have built-in generic types. Although a few years ago there was the RFC, but it was not implemented. Fortunately, there are tools for static code analysis, such as Psalm or PHPStan, which, by reading appropriate annotations in the code, are able to imitate the generic types.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts