Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rbargerhuff opened this issue Jan 24, 2022 · 1 comment

Comments

@rbargerhuff
Copy link
Contributor

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.

smaiorana added a commit to smaiorana/coder_upgrade that referenced this issue Jan 24, 2022
* backdrop-contrib#73: Conversion of a Class Property's Modifier Not Compatible with Typed Class Properties
@rbargerhuff
Copy link
Contributor Author

Here is the link to the project that demonstrates the fix.
https://github.com/smaiorana/ro_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant