Comments (2)
extract()
is a difficult function to analyse with a system like phpcs because it dynamically creates variables at runtime; it's hard to know by just looking at the code what it will do. For example:
function doSomething( $data ) {
extract( $data );
return $name;
}
In the example above, should we mark $name
as undefined or not? We can't know.
Full static analysis systems like phpstan
or psalm
may be able to handle these situations because they can follow the full flow of your code to determine every possible outcome, but this sniff is designed to operate on isolated chunks of code or single files; it doesn't know what your data actually is. If you're committed to using dynamic variable assignment, you might want to explore static analysis tools as an option instead.
I'm going to close this but feel free to reopen if you have additional questions.
from phpcs-variable-analysis.
Wow, you really know your stuff! Thank you @sirbrillig for the quick turn around.
from phpcs-variable-analysis.
Related Issues (20)
- Improve handling of initial values in initializers HOT 1
- UndefinedVariable first assigned in for loop, used in loop expression HOT 1
- Inline if-clause with short-list false positive HOT 5
- Support of array desctructing HOT 2
- Incorrect warning for arguments to static methods that return "new static()" HOT 3
- Incorrect warning for arguments are thrown on static arrow functions HOT 1
- False-positive `UndefinedVariable` for static variable inside an anonymous function HOT 4
- Incorrect warning about redeclaration of function parameter as static variable HOT 2
- Variable $this is undefined in enum HOT 1
- Support constructor promotion with readonly properties (UnusedVariable) HOT 5
- method call called 'enum' causes an "Cannot find enum start at position" error HOT 2
- Unused function parameter in lambda function HOT 4
- Ternary operator inside arrow function HOT 3
- Incorrect warning Variable $var is undefined. HOT 6
- Undefined variable error introduced in v2.11.15 HOT 2
- Feature Request: don't report on unused parameters for deprecated functions
- Variable reported as unused on an assignment by reference HOT 2
- Assignment of an array element counts as a read
- `squizlabs/PHP_CodeSniffer` is abandoned - Replace with `PHPCSStandards/PHP_CodeSniffer` when the time is right HOT 3
- List assignment next to array causes unused variable warning HOT 5
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 phpcs-variable-analysis.