Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"dependencies": {
"linguist-languages": "^8.0.0",
"php-parser": "^3.1.5"
"php-parser": "^3.2.4"
},
"devDependencies": {
"@babel/preset-env": "^7.27.2",
Expand Down
1 change: 1 addition & 0 deletions src/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
{ value: "8.0" },
{ value: "8.1" },
{ value: "8.2" },
{ value: "8.3" },
],
},
trailingCommaPHP: {
Expand Down
1 change: 1 addition & 0 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,7 @@ function printNode(path, options, print) {
node.final ? "final " : "",
node.visibility ? [node.visibility, " "] : "",
"const",
node.type ? [node.nullable ? " ?" : " ", print("type")] : "",
firstVariable ? [" ", firstVariable] : "",
indent(printed.slice(1).map((p) => [",", hardline, p])),
]);
Expand Down
57 changes: 56 additions & 1 deletion tests/class/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`anonymous.php 1`] = `
====================================options=====================================
Expand Down Expand Up @@ -918,6 +918,31 @@ readonly class ReadOnlyCls {

class FinalCost { final public const FOO = 'foo'; }

// PHP 8.3 typed class constants
enum E {
const string TEST = "Test1"; // E::TEST is a string
}

trait T {
const string TEST = E::TEST; // T::TEST is a string too
}

interface I {
const string TEST = E::TEST; // I::TEST is a string as well
}

class Foo implements I {
use T;

const string TEST = E::TEST; // Foo::TEST must also be a string
}

class Bar extends Foo {
const string TEST = "Test2"; // Bar::TEST must also be a string, but the value can change
public const int|null I = null;
public const ?int J = null;
}

=====================================output=====================================
<?php

Expand Down Expand Up @@ -1368,5 +1393,35 @@ class FinalCost
final public const FOO = "foo";
}

// PHP 8.3 typed class constants
enum E
{
const string TEST = "Test1"; // E::TEST is a string
}

trait T
{
const string TEST = E::TEST; // T::TEST is a string too
}

interface I
{
const string TEST = E::TEST; // I::TEST is a string as well
}

class Foo implements I
{
use T;

const string TEST = E::TEST; // Foo::TEST must also be a string
}

class Bar extends Foo
{
const string TEST = "Test2"; // Bar::TEST must also be a string, but the value can change
public const int|null I = null;
public const ?int J = null;
}

================================================================================
`;
25 changes: 25 additions & 0 deletions tests/class/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,28 @@ public function __construct( public int $a, private float $b, protected stri
}

class FinalCost { final public const FOO = 'foo'; }

// PHP 8.3 typed class constants
enum E {
const string TEST = "Test1"; // E::TEST is a string
}

trait T {
const string TEST = E::TEST; // T::TEST is a string too
}

interface I {
const string TEST = E::TEST; // I::TEST is a string as well
}

class Foo implements I {
use T;

const string TEST = E::TEST; // Foo::TEST must also be a string
}

class Bar extends Foo {
const string TEST = "Test2"; // Bar::TEST must also be a string, but the value can change
public const int|null I = null;
public const ?int J = null;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4701,10 +4701,10 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

php-parser@^3.1.5:
version "3.2.1"
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.2.1.tgz#960916dc03e4979a59435f9dd9eb03f2e86d8126"
integrity sha512-WT5AMqe39ZdqAxp9Yp7uR6e3clBWlT1dxHHs49GmnDx2d+975NEiLSVy2tRGLdSC9tgdQOLiN1Yz54g1d2cZDQ==
php-parser@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.2.4.tgz#56f97438a46c54ce0e78a8357782402f9530f892"
integrity sha512-X1HIaSHCb9aAReEqb+U/AAB3evE1iKD6tAY/lw9+wT4koCkWhg22m4LNtFGwd3Qv4PYIL2+zl+oXh00ALKya0Q==

picocolors@^1.0.0:
version "1.0.0"
Expand Down