vkcom / php-parser Goto Github PK
View Code? Open in Web Editor NEWPHP parser written in Go
Home Page: https://php-parser.com
License: MIT License
PHP parser written in Go
Home Page: https://php-parser.com
License: MIT License
8.0+
<?php
#
# Comment
#
$a = 100;
$a
: startLine
= 4
$a
: startLine
= 6
I want to lint PHP files, if they are syntax okay for a specific PHP version. It does work well for major versions, but not minor like 7.2, 7.4, 8.1
7.2
Code with Typed Property
It parses the file and does not complain.
Expect an error from the parser, as typed properties is available since 7.4
RFC: https://wiki.php.net/rfc/readonly_properties_v2
Example:
class User {
public function __construct(
public readonly string $name
) {}
}
We use grammar files from PHP-Parser.
The following parts need to be done.
When starting work on each item, you need to create a separate issue with a description,
and the created PR must be marked as closing the created issue.
The description should have a link to the RFC, as well as a short description + examples.
All new tests should be written in files with the php8_1_test
suffix using the tester
package. If the package
does not contain the required test type, then it is advisable to write the test suite for it in a separate PR.
7.4 and 8.0
"$property->name[]";
==> syntax error: unexpected '[' at line 2
No error.
RFC: https://wiki.php.net/rfc/enumerations
Example:
enum Suit {
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
RFC: https://wiki.php.net/rfc/final_class_const
Example:
class Foo {
final public const X = "foo";
}
8.0 8.1
class Enum{}
2023/12/15 09:35:40 syntax error: unexpected T_ENUM, expecting T_STRING at line 1
[max@max ~/src/php-parser-test]$ cat test.php
<?php
class Enum {}
[max@max ~/src/php-parser-test]$ php8.0 -l test.php
No syntax errors detected in test.php
[max@max ~/src/php-parser-test]$ php8.1 -l test.php
No syntax errors detected in test.php
5.6
data:=`<?php assert($_GET[1]);/*`
Parsing failed:
syntax error: unexpected '/' at line 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.