php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62544 A function alternative to "php -l"
Submitted: 2012-07-12 19:53 UTC Modified: 2021-06-03 08:56 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: narf at bofh dot bg Assigned: krakjoe (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: narf at bofh dot bg
New email:
PHP Version: OS:

 

 [2012-07-12 19:53 UTC] narf at bofh dot bg
Description:
------------
Currently, there's no way to do a syntax check from within a script (unless we do something like `/usr/bin/php -l /path/to/script.php`) and there deffinately are use cases for such a feature.

Considering that the actual checking logic is already available, it shouldn't be hard at all to make a function alternative to it.

Here's what the function description would look like:

    bool php_syntax_check( string $target [, bool $raw_code = FALSE] )

$target is the script file path, unless $raw_code is set to TRUE. In the latter case - $target is raw php code, as it would be passed to eval().


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-15 14:24 UTC] reeze dot xia at gmail dot com
There ever a function for this: http://php.net/manual/en/function.php-check-
syntax.php (you  could take a look at those user-land implementations in User 
Contributed Notes sectiion)

php_check_syntax(), it was removed after 5.0.5.
the reason is here: https://bugs.php.net/bug.php?id=27406
 [2012-07-15 15:01 UTC] narf at bofh dot bg
So, it used to exist, but due to poor design and implementation it's removed instead of fixed and we're forced to create hacks? This doesn't sound smart.
 [2012-07-15 16:29 UTC] reeze dot xia at gmail dot com
Yes, I could like it back too.
So +1 for this request :)
 [2021-06-03 08:56 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2021-06-03 08:56 UTC] krakjoe@php.net
At the time these requests were made, the design of the compiler prohibited a simple implementation (such as the one merged and then removed), although it would have been possible the decision to remove was likely informed by just how many edge cases there would have been.

Today, the design of the compiler allows for a trivial implementation in userland using token_get_all.

In addition the ecosystem has a much more robust method of inspecting source code in PhpParser.

Since this no longer seems to be a real problem, closing this one.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jun 24 10:01:23 2021 UTC