-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.3 Support: Typed class constants (Part 6)
- #6701 - https://wiki.php.net/rfc/typed_class_constants - Fix the formatter (don't add spaces within parens of DNF types) - Fix the `UnusableTypeHintError` - Add unit tests
- Loading branch information
Showing
13 changed files
with
685 additions
and
10 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
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
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
81 changes: 81 additions & 0 deletions
81
php/php.editor/test/unit/data/testfiles/formatting/php83/typedClassConstants_01.php
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,81 @@ | ||
<?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 A implements Stringable { | ||
public function __toString() { | ||
return static::class; | ||
} | ||
} | ||
|
||
class B extends A {} | ||
class C extends A {} | ||
|
||
class ClassTest { | ||
public const WITHOUT_TYPE = 1; | ||
public const ?int NULLABLE = 1; | ||
private const A | B UNION = D_A; | ||
protected const A & B INTERSECTION = D_B; | ||
public const (A &B ) | C DNF = D_C; | ||
public const string STRING = 'a'; | ||
public const int INT = 1; | ||
public const float FLOAT = 1.5; | ||
public const bool BOOL = true; | ||
public const array ARRAY = ['t', 'e', 's', 't']; | ||
public const iterable ITERABLE = [ 'a', 'b', 'c']; | ||
public const mixed MIXED = 1; | ||
public const object OBJECT = D_A; | ||
public const string | array UNION2 = 'a' , UNION3 = ['a']; | ||
#[Attr] | ||
public const int | null UNION4 = null; | ||
} | ||
|
||
interface InterfaceTest { | ||
const string STRING = "string"; | ||
public const ? int NULLABLE = 1; | ||
public const A|B UNION = D_A; | ||
public const A&B INTERSECTION = D_B; | ||
public const ( A & B ) |C DNF = D_C; | ||
} | ||
|
||
trait TraitTest { | ||
const string STRING = "string"; | ||
public const ?int NULLABLE = 1; | ||
private const A|B UNION = D_A; | ||
protected const A&B INTERSECTION = D_B; | ||
public const (A&B)|C DNF = D_C; | ||
} | ||
|
||
enum EnumTest { | ||
const string STRING = "string"; | ||
public const ? int NULLABLE = 1; | ||
private const A| B UNION=D_A; | ||
protected const A&B INTERSECTION=D_B; | ||
public const (A & B) | (A&C ) DNF=D_C; | ||
public const static A=EnumTest :: Test; | ||
|
||
case Test; | ||
} | ||
|
||
define("D_A", new A()); | ||
define("D_B", new B()); | ||
define("D_C", new C()); | ||
|
||
echo ClassTest::DNF . PHP_EOL; | ||
var_dump(ClassTest::DNF); |
93 changes: 93 additions & 0 deletions
93
...estfiles/formatting/php83/typedClassConstants_01.php.testTypedClassConstants_01.formatted
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,93 @@ | ||
<?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 A implements Stringable { | ||
|
||
public function __toString() { | ||
return static::class; | ||
} | ||
} | ||
|
||
class B extends A { | ||
|
||
} | ||
|
||
class C extends A { | ||
|
||
} | ||
|
||
class ClassTest { | ||
|
||
public const WITHOUT_TYPE = 1; | ||
public const ?int NULLABLE = 1; | ||
private const A|B UNION = D_A; | ||
protected const A&B INTERSECTION = D_B; | ||
public const (A&B)|C DNF = D_C; | ||
public const string STRING = 'a'; | ||
public const int INT = 1; | ||
public const float FLOAT = 1.5; | ||
public const bool BOOL = true; | ||
public const array ARRAY = ['t', 'e', 's', 't']; | ||
public const iterable ITERABLE = ['a', 'b', 'c']; | ||
public const mixed MIXED = 1; | ||
public const object OBJECT = D_A; | ||
public const string|array UNION2 = 'a', UNION3 = ['a']; | ||
|
||
#[Attr] | ||
public const int|null UNION4 = null; | ||
} | ||
|
||
interface InterfaceTest { | ||
|
||
const string STRING = "string"; | ||
public const ?int NULLABLE = 1; | ||
public const A|B UNION = D_A; | ||
public const A&B INTERSECTION = D_B; | ||
public const (A&B)|C DNF = D_C; | ||
} | ||
|
||
trait TraitTest { | ||
|
||
const string STRING = "string"; | ||
public const ?int NULLABLE = 1; | ||
private const A|B UNION = D_A; | ||
protected const A&B INTERSECTION = D_B; | ||
public const (A&B)|C DNF = D_C; | ||
} | ||
|
||
enum EnumTest { | ||
|
||
const string STRING = "string"; | ||
public const ?int NULLABLE = 1; | ||
private const A|B UNION = D_A; | ||
protected const A&B INTERSECTION = D_B; | ||
public const (A&B)|(A&C) DNF = D_C; | ||
public const static A = EnumTest::Test; | ||
|
||
case Test; | ||
} | ||
|
||
define("D_A", new A()); | ||
define("D_B", new B()); | ||
define("D_C", new C()); | ||
|
||
echo ClassTest::DNF . PHP_EOL; | ||
var_dump(ClassTest::DNF); |
Oops, something went wrong.