Comments (9)
Is this a short array definition issue?
I assume the source should look something like this, if it was including php5.3 support.
echo (new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts'))->render(
array(
'results' => $results,
'enabled' => $enabled,
)
)
The sniffs are currently (and in the phpcs2 draft) rejecting short array use as to maintain compatibility with Joomla projects still supporting php5.3 (Oh the things we could do if php5.3 was truly dead and not supported by Joomla projects)
from coding-standards.
Changed it to run with full array syntax and the same error.
That sniff looks for the next token after one of the registered tokens and if it's an open parenthesis it raises an error. So it won't accept PHP 5.4 syntax in this context.
from coding-standards.
Looking at the source pear sniff, we added the tokens T_CLONE, and T_ECHO
on echo is where I think it's throwing the error
Since echo is not actually a function (it is a language construct) the brackets are not required. but I'm not sure about echo 's behavior when followed immediately by new...
If I follow the Brackets right I think there is a misplaced one before the render call that should be at the end
echo (new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts')->render(
array(
'results' => $results,
'enabled' => $enabled,
)
))
Which would follow the format
$layout = new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts');
echo $layout->render(array('results' => $results, 'enabled' => $enabled,));
or the format
$layout = new JLayoutFile('install.result', JPATH_ADMINISTRATOR . '/components/com_podcastmanager/layouts');
$data = array('results' => $results, 'enabled' => $enabled,);
echo $layout->render($data);
from coding-standards.
That looks about right at a quick glance. Basically, a sequence of T_ECHO
T_OPEN_PARENTHESIS
T_NEW
should be allowed but right now the sniffer is groaning because of the T_OPEN_PARENTHESIS
being present.
from coding-standards.
So we need to decide if echo
can be allowed to use parenthesis. if yes, then that token should be removed from the sniff.
from coding-standards.
I personally don't care either way as long as it allows PHP 5.4 syntax. I get Joomla still supports 5.3 code but that shouldn't force us who aren't to write code resembling it. If that means echo in general allows echo (T_WHATEVER);
statements as a side effect I guess we'll have to accept it.
from coding-standards.
Looking deeper at the sniff, Short array is a separate question enforced by other sniffs. (sorry, I shot off the cuff with my first response assuming the short array was the cause).
I think in the phpcs2 draft it's a question of Generic.Arrays.DisallowShortArraySyntax as an included or excluded sniff.
For this error it's the specific to the T_ECHO
token in the sniff. We remove that token we then get echo (T_WHATEVER);
statements being allowed.
from coding-standards.
Honestly, we're probably better off removing it. Between the T_ECHO
T_OPEN_PARENTHESIS
T_NEW
sequence and echoing a typecast object (echo (int) $object->getCount();
) it might be more trouble than it's worth to enforce it.
from coding-standards.
Fixed in the PHPCS2 draft branch as well.
from coding-standards.
Related Issues (20)
- [2.x] More Indention Issues With Closures HOT 2
- [4.0] Anonymous class support HOT 5
- [RFC] Multiline Signature Formatting HOT 4
- Analysis.md - 404 error on link from website HOT 2
- support for vscode HOT 8
- Indentation Confusion HOT 1
- Require visibility for class constants HOT 2
- Support new magic methods in PHP 7.4 HOT 3
- phpstorm 2019.2 doesn't follow settings HOT 2
- typos in README
- New Lines in XML-Files
- Indention checks fail with static Closure
- @since -> @SInCE HOT 1
- @headers link to invalid GitHub pages HOT 1
- Can we change standard from <br /> to <br> ? HOT 4
- Documentation - How should database table and column names be written HOT 3
- [PHP8] Document named arguments BC policy HOT 1
- Links in joomla site not working HOT 1
- problem in alternative syntax (controller statements)
- PSR12 mention in README.md
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coding-standards.