The phpscript vm already allows fn, func and function to define a function. This makes the code less wordy on definitions.
<?php
class Test {
function isValid() {
echo "Test OK";
}
function isAdmin() {
return false;
}
}
The above is valid PHP syntax.
<?php
class Test {
fn isValid() {
echo "Test OK";
}
func isAdmin() {
return false;
}
}
The above syntax is valid phpscript syntax.
I'm filing this issue to consider omitting the function keyword in a class definition.
<?php
class Test {
isValid() {
echo "Test OK";
}
isAdmin() {
return false;
}
}
To control the behaviour, runner.Options should include a StrictMode flag. If true:
- only
function will be accepted to match PHP function definitions,
- if/for and other statements must be parenthesised
if (...)
If false:
- use
fn, func or omit the keyword for class methods
- relaxed parenthesis rules for conditions and related statements
- optional / trimmed ending line semicolons
- code is incompatible with the PHP runtime (
$this->name instead of array($this, "name") works...)
Considerations:
- namespaces and class autoloading are still difficult, but I may want to use them as an author to vendor code,
- call_user_func_array (and missing call_user_func) should support php array($this, "name") for a callable reference,
Out of scope / won't do:
- do we type hint a callable?
- do we type hint function arguments?
- do we type hint returns (php returns have 'array' not
[]T)?
The answer is probablly no, but I'd consider tweaking this syntax further in the future as opt-in.
The phpscript vm already allows
fn,funcandfunctionto define a function. This makes the code less wordy on definitions.The above is valid PHP syntax.
The above syntax is valid phpscript syntax.
I'm filing this issue to consider omitting the function keyword in a class definition.
To control the behaviour, runner.Options should include a StrictMode flag. If true:
functionwill be accepted to match PHP function definitions,if (...)If false:
fn,funcor omit the keyword for class methods$this->nameinstead ofarray($this, "name")works...)Considerations:
Out of scope / won't do:
[]T)?The answer is probablly no, but I'd consider tweaking this syntax further in the future as opt-in.