Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php 8 Stubs Laravel Package

phpstan/php-8-stubs

Stub files for PHP 8 built-in functions, classes, and extensions, maintained for PHPStan. Improves static analysis and type inference by providing accurate signatures and phpDoc where native reflection is incomplete or inconsistent.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Synergy: The package complements Laravel’s PHP 8.x+ focus by providing precise type stubs for core PHP classes (e.g., stdClass, DateTime, Exception), which are heavily used in Laravel’s ecosystem (e.g., Eloquent models, request handling, and service containers). This enables Laravel’s strict_types=1 directive to work effectively with static analysis tools like PHPStan.
  • Static Analysis Alignment: Laravel’s adoption of PHPStan (via packages like nunomaduro/phpinsights or custom configurations) makes this package a natural fit. It bridges the gap between Laravel’s dynamic features (e.g., magic methods, dynamic properties) and stricter type checking.
  • Non-Invasive Integration: The stubs are passive and do not modify Laravel’s runtime behavior. They integrate seamlessly with existing tooling (PHPStan, IDEs, CI/CD) without requiring changes to Laravel’s core or business logic.

Integration Feasibility

  • Drop-in Compatibility: The package requires no Laravel-specific modifications. It works at the PHP language level, making it compatible with any Laravel project using PHP 8.0+.
  • Version Alignment: Laravel 9+ (PHP 8.0+) is fully supported. For Laravel 8.x (PHP 7.4), this package is irrelevant, but Laravel’s migration to PHP 8.x aligns with its long-term support (LTS) roadmap.
  • Toolchain Harmony: Works seamlessly with:
    • PHPStan: Enhances Laravel’s existing static analysis by providing accurate type information for PHP 8.x features (e.g., union types, named arguments, attributes).
    • IDE Tooling: Improves autocompletion and type checking in PHPStorm, VSCode, or Laravel-specific IDE plugins (e.g., Barbauli/Sentinel for Laravel).
    • CI/CD Pipelines: Can be added to Laravel’s static analysis stages (e.g., GitHub Actions, GitLab CI) without disrupting existing workflows.

Technical Risk

  • False Positives/Negatives: Laravel’s dynamic features (e.g., magic methods like __get(), __call(), dynamic properties) may trigger false positives or negatives. For example:
    • Risk: PHPStan might flag dynamic property access as undefined.
    • Mitigation: Configure PHPStan to ignore dynamic properties or use phpstan/extension-installer to add Laravel-specific rules.
  • Performance Overhead: Static analysis adds CPU/memory usage, which could slow down Laravel’s development workflow or CI pipelines.
    • Mitigation: Cache PHPStan results (e.g., --generate-baseline) and run analysis in parallel (--parallel). Exclude tests or third-party code from strict checks.
  • Deprecation Risk: PHP 8.x stubs may become outdated if PHPStan or PHP evolves (e.g., new PHP 9.x features).
    • Mitigation: Monitor upstream updates and test against new Laravel/PHP versions. Use version pins in composer.json.
  • Legacy Code Exposure: Laravel projects with legacy PHP 7.x codebases may reveal type-related issues during migration.
    • Mitigation: Phase adoption by focusing on critical paths (e.g., APIs, payment processing) before applying to the entire codebase.

Key Questions

  1. Current Static Analysis State:
    • Is PHPStan already integrated into the Laravel project? If so, what is the current configuration (e.g., phpstan.neon rules, severity levels)?
    • Are there existing false positives/negatives in PHPStan that could be exacerbated by this package?
  2. PHP Version Strategy:
    • Is the project locked to PHP 8.0–8.2, or is PHP 9.x in scope? Will stubs need updates for newer PHP features?
    • How is PHP version consistency enforced in CI/CD (e.g., Docker, Laravel Sail)?
  3. Tooling Integration:
    • How is PHPStan currently invoked (CLI, IDE, CI)? Will this package require updates to the phpstan.neon configuration?
    • Are there other static analysis tools (e.g., Psalm, InstaPHPC) that could conflict or complement this package?
  4. CI/CD Impact:
    • What is the acceptable runtime for static analysis in CI? Could this package slow down Laravel’s pipeline?
    • Is caching (e.g., GitHub Actions cache) already implemented for PHPStan?
  5. Team Readiness:
    • Is the team comfortable adopting stricter type checking? Will this require training or cultural shifts?
    • Are there specific Laravel features (e.g., dynamic properties, magic methods) that might cause friction?
  6. Laravel-Specific Considerations:
    • How are custom Laravel classes (e.g., Eloquent models, service providers) handled? Will stubs need extension for these?
    • Are there third-party Laravel packages that might conflict with the stubs (e.g., packages using reflection or dynamic code)?

Integration Approach

Stack Fit

  • Primary Use Case: Enhance PHPStan’s type checking for Laravel applications using PHP 8.x, particularly for:
    • Core Laravel Classes: Improve type accuracy for Illuminate\Support\Collection, Illuminate\Http\Request, and Illuminate\Database\Eloquent\Model.
    • Custom Logic: Catch type-related bugs in business logic, APIs, and service layers.
    • Legacy Modernization: Retrofit type hints to PHP 7.x codebases during migration to PHP 8.x.
  • Secondary Use Cases:
    • Improve IDE tooling (e.g., PHPStorm’s "Inspect Code" with better Laravel-specific type inference).
    • Validate interactions with third-party packages (e.g., spatie/laravel-permission, laravel/breeze).
  • Non-Use Cases:
    • Not a replacement for runtime type systems (e.g., spatie/fork for PHP 7.x).
    • Not a performance-critical path (static analysis is pre-runtime and does not affect Laravel’s production performance).

Migration Path

  1. Assessment Phase:
    • Audit the current PHPStan configuration (phpstan.neon) for Laravel-specific rules or exclusions.
    • Run PHPStan locally with the new stubs to identify immediate issues, focusing on:
      • Core Laravel classes (e.g., Request, Collection).
      • Custom business logic layers.
    • Benchmark CI runtime impact by testing with a subset of the codebase.
  2. Incremental Rollout:
    • Step 1: Install and Configure: Add the stubs to composer.json:
      "require-dev": {
        "phpstan/php-8-stubs": "^1.0",
        "phpstan/extension-installer": "^1.0" // Optional: for Laravel-specific rules
      }
      
      Update phpstan.neon to include stubs:
      includes:
        - vendor/phpstan/php-8-stubs/stubs/
      
    • Step 2: Laravel-Specific Tweaks: Use phpstan/extension-installer to add Laravel rules (e.g., for magic methods):
      vendor/bin/phpstan-extensions install --symfony --laravel
      
      Configure PHPStan to ignore dynamic properties or handle Laravel’s magic methods:
      arguments:
        dynamicPropertyAccess:
          - allowMagicPropertyAccess: true
      
    • Step 3: Pilot Testing: Test the stubs on a non-critical Laravel module (e.g., a legacy feature or internal tool) to validate accuracy and performance.
  3. Validation:
    • Compare PHPStan results with/without stubs. Prioritize fixing legitimate errors (e.g., undefined methods, incorrect return types).
    • Benchmark CI runtime and adjust caching or parallelism as needed.

Compatibility

  • Laravel Versions: Compatible with Laravel 9+ (PHP 8.0+). For Laravel 8.x (PHP 7.4), this package is irrelevant but aligns with Laravel’s LTS roadmap.
  • PHP Extensions: No direct dependencies, but stubs may expose issues with:
    • Dynamic Laravel Features: Magic methods (e.g., __get(), __call()), dynamic properties, or reflection-heavy code.
    • Third-Party Packages: Packages using dynamic code (e.g., laravel/ide-helper) may need updates.
  • Package Conflicts: Low risk—stubs are passive. Potential conflicts if another package ships its own stubs (unlikely) or if Laravel-specific extensions (e.g., phpstan/laravel) are already in use.

Sequencing

  1. Pre-requisite: Ensure PHPStan is already integrated into the Laravel project (even if minimally configured).
  2. Parallel Task: Align with other Laravel-specific static analysis improvements:
    • Install phpstan/laravel for Laravel-specific rules.
    • Configure phpstan/extension-installer for Symfony/Laravel compatibility.
  3. Post-Integration:
    • Update Laravel-specific documentation to reflect stricter type expectations.
    • Train developers on interpreting PHPStan errors with the new stubs, particularly for Laravel’s dynamic features.
    • Explore extending stubs for custom Laravel classes if needed (e.g., using phpstan/auto-import).

Operational Impact

Maintenance

  • Dependency Management:
    • Monitor `
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity