[ 
https://issues.apache.org/jira/browse/THRIFT-5960?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Volodymyr Panivko updated THRIFT-5960:
--------------------------------------
    Description: 
After the PSR-12 sweep lands, the PHP runtime library still uses
PHPDoc-only typing — zero native parameter types, zero return types,
zero typed properties, no declare(strict_types=1).

This ticket lands all three in one pass:

  * declare(strict_types=1) in every file under lib/php/lib/ and
    lib/php/test/.
  * Native parameter and return types for the public API: TTransport,
    TProtocol, TServer, TBase, TException, all Factory and Server
    classes, all Transport and Protocol implementations.
  * Typed properties wherever it is safe.
  * Constructor property promotion in pure-assignment Factory classes.
  * Native by-ref types in TProtocol abstract methods (PHP 8.1
    supports types on by-ref params).
  * Replace function_exists() runtime checks in TBinarySerializer,
    TSocket, TSocketPool with cached capability flags.
  * Selective switch -> match conversion in pure dispatchers; keep
    switch where there is fall-through.
  * After the sweep, raise phpstan level from 1 to a higher value (5
    or higher; to be decided based on what the new baseline looks
    like) and shrink the baseline accordingly.

This is a breaking change for downstream code that subclasses public-
API abstract bases (TTransport, TProtocol, TServer, TBase, TException).
Plain users of the library are not affected. Generated structs that
extend TBase continue to work because TBase::read/write retain loose
TProtocol-typed parameters without array shape constraints.

  was:
The PHP coding standard documented at lib/php/coding_standards.md is
PSR-2 (frozen since 2019; superseded by PSR-12). The PHP-CodeSniffer
config at phpcs.xml.dist still pins it. Meanwhile, generated PHP code
emitted by the C++ generator at compiler/cpp/src/thrift/generate/
t_php_generator.cc has its own hand-written formatting that does not
follow either standard precisely.

This ticket adopts PSR-12 across both surfaces in one cycle to avoid
two style families coexisting in the repo:

  * Add friendsofphp/php-cs-fixer as a require-dev dependency.
  * Add lib/php/.php-cs-fixer.dist.php with @PSR12 + @PHP81Migration
    presets (see roadmap doc for full ruleset).
  * Run php-cs-fixer fix once across lib/php/lib/ and lib/php/test/ to
    reformat to PSR-12.
  * Update phpcs.xml.dist to reference PSR12 instead of PSR2 (or remove
    it if cs-fixer fully replaces it — to be decided in PR).
  * Update lib/php/coding_standards.md to point at PSR-12.
  * Update C++ generator emission in t_php_generator.cc so newly
    generated PHP matches PSR-12: indentation, blank lines, brace
    placement, namespace block, use ordering.
  * Regenerate golden test fixtures under test/php/gen-php/,
    test/php/gen-phpi/, test/php/gen-php-classmap/.
  * Add lib-php-quality CI step that runs php-cs-fixer in --dry-run
    mode (alongside the existing phpstan step from THRIFT-5957).

This is a breaking change for downstream users whose own coding-style
linters rely on the previous format of generated files. Plain runtime
behaviour is unaffected — pure formatting.


> Adopt strict_types and native parameter / return / property types in 
> lib/php/lib/
> ---------------------------------------------------------------------------------
>
>                 Key: THRIFT-5960
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5960
>             Project: Thrift
>          Issue Type: New Feature
>          Components: PHP - Library
>    Affects Versions: 0.24.0
>            Reporter: Volodymyr Panivko
>            Assignee: Volodymyr Panivko
>            Priority: Major
>
> After the PSR-12 sweep lands, the PHP runtime library still uses
> PHPDoc-only typing — zero native parameter types, zero return types,
> zero typed properties, no declare(strict_types=1).
> This ticket lands all three in one pass:
>   * declare(strict_types=1) in every file under lib/php/lib/ and
>     lib/php/test/.
>   * Native parameter and return types for the public API: TTransport,
>     TProtocol, TServer, TBase, TException, all Factory and Server
>     classes, all Transport and Protocol implementations.
>   * Typed properties wherever it is safe.
>   * Constructor property promotion in pure-assignment Factory classes.
>   * Native by-ref types in TProtocol abstract methods (PHP 8.1
>     supports types on by-ref params).
>   * Replace function_exists() runtime checks in TBinarySerializer,
>     TSocket, TSocketPool with cached capability flags.
>   * Selective switch -> match conversion in pure dispatchers; keep
>     switch where there is fall-through.
>   * After the sweep, raise phpstan level from 1 to a higher value (5
>     or higher; to be decided based on what the new baseline looks
>     like) and shrink the baseline accordingly.
> This is a breaking change for downstream code that subclasses public-
> API abstract bases (TTransport, TProtocol, TServer, TBase, TException).
> Plain users of the library are not affected. Generated structs that
> extend TBase continue to work because TBase::read/write retain loose
> TProtocol-typed parameters without array shape constraints.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to