Comments (5)
hmm... Still trying to see the use case here.
I'm also wondering how stable the result would be, keeping in mind that, in many cases, files that define global functions do more than just that: They contain directly executable code.
You'd also have to topologically sort the requires in case functions are called in these directly executable lines of code as they may require other functions to be loaded before that to work. Same goes for constant definitions, as define
can be used with a function (e.g. define('foo', (function(){return 'bar';})());
). So you'd also have to actually parse the code for function calls.
Could of course be done. But what's different from having a regular bootstrap script that loads the generated autoloader file and whatever list of files you need to get the functions in? Why would it be added to the autoloader file?
I'm not trying to avoid adding features to phpab
. It's a lot of work to create something that has a chance of being stable. Not sure if it's worth the effort, particularly given that I consider that a very undesirable way of creating software ;)
from autoload.
PHP does not support autoloading for functions, so I don't see what an autoload generator can do here?
How would you trigger it? If you wrap the functions in a class and make all methods static, you could do class::method()
. Given it's a class, you'd have autoloading again.
from autoload.
I don't think there's anything to be done here.
from autoload.
Actually, I was looking at the code and thinking that, upon detection of a function, it adds the file to a set of files that contain functions.
Using that set, it compiles a static list of requires that have exported constants and functions in them, which is appended to the end of the auto load file, after whatever is done for classes, interfaces and traits (depending on whether static is set).
from autoload.
Hrm, the same could be said for classes. There are projects that do that too. It’d be daft to expect a tool to support generating a list of requires that are required by function calls. But I see what you mean.
I’m writing a library that defines lots of pure functions. I wasn’t thinking about side effects at all - including any file in my project has only the effect of defining functions, constants (I.e callable constants) and other symbols. Never side effects.
I was simply looking for a solution where I’m not having to list all of my files in composer to generate an autoloader, instead listing just one, generated file as part of the build. A quick script that recurses my source folder does the trick. I was simply wondering if a tool that generated the same for interfaces/classes did the same for functions too, recognising that only requires need to be generated.
from autoload.
Related Issues (20)
- CI: move to GH Actions ? HOT 2
- Deprecation warning when running on PHP 8.2 HOT 2
- Integration within Box HOT 7
- Exclude directory HOT 2
- Make `--phar` reproducible HOT 34
- Add option to handle duplicate declarations across multiple files HOT 2
- Do not bail out on first duplicate code unit HOT 1
- evaluate introducing an "opcache prewarm list" HOT 1
- Add support for Composer's autolaoder and adding autoloading in code HOT 3
- Error with recursive Composer dependencies HOT 1
- Dep missing in Readme
- symfony/event-dispatcher Duplicate definitions of the following unit(s) found HOT 2
- `__halt_compiler` detection HOT 7
- Warnings and Notices in ComposerIterator
- Zeta Components ConsoleTools uses PHP syntax deprecated in PHP 7.4 HOT 1
- PHPAB 1.25.7 generates broken PHAR for PHPUnit
- Adopt, if needed, to PHP 8's T_NAME_FULLY_QUALIFIED, T_NAME_RELATIVE, and T_NAME_QUALIFIED tokens HOT 3
- Can't generate autoloader for nikic/php-parser HOT 2
- Array to string conversion on parsing composer.json HOT 3
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 autoload.