forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.4 Support: Property hooks (Part 4)
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/property-hooks - Fix the folding feature - Add unit tests
- Loading branch information
Showing
8 changed files
with
614 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
php/php.editor/test/unit/data/testfiles/propertyHooks.php.folds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
+ /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
- */ | ||
+ class PropertyHooksClass { | ||
| public const string CONSTANT = "property hook"; | ||
| // valid properties | ||
+ public $valid01 { | ||
+ get { | ||
| return $this->prop1; | ||
- } | ||
+ set { | ||
| $this->valid01 = $value; | ||
- } | ||
- } | ||
+ public int $valid02 = 1 { | ||
+ get { | ||
| echo __METHOD__, "\n"; | ||
| return $this->valid02; | ||
- } | ||
+ set($value){ | ||
| $this->valid02 = $value; | ||
- } | ||
- } | ||
+ public $valid03 = "string" { | ||
+ get { | ||
| return $this->valid03; | ||
- } | ||
+ set {} | ||
- } | ||
+ public string $valid04 = self::CONSTANT { | ||
+ get => $this->valid04; | ||
+ set {} | ||
- } | ||
+ public array $valid05 = [] { | ||
+ get => $this->valid05; | ||
+ set => $this->valid05 = $value; | ||
- } | ||
+ public private(set) string $valid06 = self::CONSTANT { | ||
+ get { | ||
| return $this->valid06 . "test"; | ||
- } | ||
+ set {} | ||
- } | ||
+ public $valid07 { // virtual | ||
+ get => $this->test(); | ||
+ set => $this->test() . $value; | ||
- } | ||
+ public string $valid08 { | ||
+ set(string|array $param) { | ||
| $this->valid08 = is_array($param) ? join(', ', $param) : $param; | ||
- } | ||
- } | ||
+ public $valid09 { | ||
+ #[Attr1] get {} | ||
+ #[Attr2] set {} | ||
- } | ||
+ public $valid10 = 100 { | ||
+ get { | ||
| yield 1; | ||
| yield $this->valid10; | ||
| yield 3; | ||
- } | ||
- } | ||
+ public $valid11 { // virtual | ||
+ get { | ||
| yield 1; | ||
| yield 2; | ||
| yield 3; | ||
- } | ||
- } | ||
+ public $valid12 { | ||
+ set(#[SensitiveParameter] $value) { | ||
| throw new Exception('test'); | ||
- } | ||
- } | ||
+ public $valid13 { | ||
+ final get { return 100; } | ||
- } | ||
+ final public $valid14 { | ||
+ final get => $this->valid14; | ||
- } | ||
+ public $valid15 { | ||
+ &get => $this->valid15; | ||
- } | ||
+ public $closure { | ||
+ get { | ||
| return function () { | ||
| return $this->closure; | ||
| }; | ||
- } | ||
- } | ||
+ public $arrowFunction { | ||
+ get { | ||
| return fn() => $this->arrowFunction; | ||
- } | ||
- } | ||
+ private $propertyConst { | ||
+ get => __PROPERTY__; | ||
- } | ||
+ var $var { get => 100; } | ||
| | ||
| // invalid properties | ||
+ public $invalidEmptyHook {} // error but parser allows | ||
+ private $invalidPrivateFinal { final get; } // error but parser allows | ||
+ private $invalidPublic01 { | ||
| public get; // error but parser allows | ||
- } | ||
+ public $invalidStatic01 { | ||
+ static get {} // error but parser allows | ||
- } | ||
+ public static $invalidStatic02 { // error but parser allows | ||
| get; | ||
| set; | ||
- } | ||
+ public $invalidGetParam { | ||
+ get() { // error but parser allows | ||
| var_dump($value); | ||
- } | ||
- } | ||
+ public readonly int $invalidReadonly { get{} set{} } // error but parser allows | ||
+ public $invalidSetRef { | ||
+ set(&$value) {} // error but parser allows | ||
- } | ||
+ public $invalidVariadic { | ||
+ set(...$value) {} // error but parser allows | ||
- } | ||
+ public $invalidUnknownHook { | ||
+ unknown {} // error | ||
- } | ||
- } | ||
|
||
+ class Child extends PropertyHooksClass { | ||
+ public $prop = 100 { | ||
+ get => parent::$prop::get(); | ||
+ set { | ||
| parent::$prop::set($value); | ||
- } | ||
- } | ||
- } | ||
|
48 changes: 48 additions & 0 deletions
48
php/php.editor/test/unit/data/testfiles/propertyHooksAbstract.php.folds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
+ /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
- */ | ||
+ abstract class AbstractClass { | ||
| // valid properties | ||
+ public abstract $valid01 { // OK | ||
| get; | ||
| set; | ||
- } | ||
+ public abstract $valid02 { // OK | ||
| get; | ||
+ set { | ||
| echo __METHOD__ . PHP_EOL; | ||
- } | ||
- } | ||
+ public abstract $valid03 { // OK | ||
+ get { | ||
| echo __METHOD__ . PHP_EOL; | ||
- } | ||
| set; | ||
- } | ||
+ protected abstract int $valid04 { get; set; } // OK | ||
| | ||
| // invalid properties | ||
+ public abstract $invalid01 { // error | ||
+ get{} | ||
+ set{} | ||
- } | ||
+ private abstract int $invalid02 { get; set; } // error | ||
| abstract public $invalid03; // error | ||
- } | ||
|
Oops, something went wrong.