Coder Social home page Coder Social logo

Functions about autoload HOT 5 CLOSED

theseer avatar theseer commented on September 18, 2024
Functions

from autoload.

Comments (5)

theseer avatar theseer commented on September 18, 2024 1

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.

theseer avatar theseer commented on September 18, 2024

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.

theseer avatar theseer commented on September 18, 2024

I don't think there's anything to be done here.

from autoload.

jwdunne avatar jwdunne commented on September 18, 2024

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.

jwdunne avatar jwdunne commented on September 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.