Skip to content

Conversion of a Class Property's Modifier Not Compatible with Typed Class Properties #73

@rbargerhuff

Description

@rbargerhuff

Hello,

Several of our in-house modules are no-longer backwards compatible with PHP 5.x. A lot of our modules have been upgraded to take advantage of certain changes and features introduced in PHP 7.x. Currently, we try to be compliant up to PHP 7.4.x which introduced typed properties. We have discovered that Coder Upgrade w/ Grammar Parser 1.x does not support typed properties and the conversion result ends up being syntactically incorrect.

Original Code Example:

class MyInteger {
  public int $my_integer;
  protected ?bool $plus_one = FALSE;

  public function __construct($my_integer, $plus_one) {
    $this->my_integer = $my_integer;
    $this->plus_one = $plus_one;
  }

  public function get_my_integer() {
    $my_integer = $this->my_integer;

    if ($this->plus_one) {
      $my_integer += 1;
    }

    return $my_integer;
  }
}

Converted Code:

class MyInteger {
  public int $my_integer;
  public protected bool $plus_one = FALSE;

  public protected public function __construct($my_integer, $plus_one) {
    $this->my_integer = $my_integer;
    $this->plus_one = $plus_one;
  }

  public function get_my_integer() {
    $my_integer = $this->my_integer;

    if ($this->plus_one) {
      $my_integer += 1;
    }

    return $my_integer;
  }
}

We have a fork in progress that addresses this issue and we will be submitting a PR for this issue soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions