Comments (14)
Sorry for the spam in here, didn't realize that GitHub would pull in my change logs... :)
from assert.
I disagree with this change, as this is not a failure in this package or in composer. The problem only exists when someone uses require 'vendor/autoload.php'
instead of using require_once
. This lowers the performance (a minuscule amount, I know) of every single request.
from assert.
Which is to say, the problem should have been resolved by submitting patches to the offending WP plugins, instead of brute forcing a solution in this package.
from assert.
@shadowhand The problem is not due to WP plugins. This problem exists any time you have an app/framework that doesn't use Composer at the root level, and you still want to use Composer for whatever extension mechanism it uses. It is a limitation of PHP (that cannot autoload functions, only class-like elements), and the above patch just makes sure the assert
library can still be used in such scenarios.
from assert.
Ah, btw, just wanted to state that require_once
will not fix the above issue in many cases, as it does not work on basis of the class to load, but rather on the filepath to retrieve the class from. If you require_once
the same file from two different locations, both will be loaded.
from assert.
If you
require_once
the same file from two different locations, both will be loaded.
That's an incorrect statement. As per the docs:
The
require_once
statement is identical torequire
except PHP will check if the file has already been included, and if so, not include (require) it again.
from assert.
Yes, but it checks this by comparing the (normalized) absolute path. If you require the same file from two different locations on your filesystem/Phar/stream, require_once
will not notice that these are the same.
That being said, Composer does not use require_once
, but rather a standard require
in its "files"
autoloader: https://github.com/composer/composer/blob/master/src/Composer/Autoload/AutoloadGenerator.php#L715
from assert.
I still don't understand the problem. Is this a problem with trying to combine composer and manual file loading?
from assert.
The problem is that, as soon as you use "procedural code" with Composer, it uses the "files"
hack to simulate autoloading. However, this is no real autoloading (as it is not supported by PHP), so it behaves differently than normal autoloading.
And whereas you can freely combine Composer autoloaders and other autoloaders in whatever layouts and hierarchies as you see fit in a legacy application (meaning one you cannot just build from the ground up from one composer.json
file), this all breaks with fatal errors if you do declarations in files that are loaded through the Composer "files"
mechanism.
The above is an easy way to allow the beberlei/assert
library to work under non-optimal conditions without breaking. This cannot be solved by the consuming code, because the problem is embedded in Composer's autoloader generator.
from assert.
Still not making sense. If you're using composer everywhere, and you always use require_once __DIR__ . '/some/path/to/autoload.php';
will anything break? I can't see why it would.
from assert.
I'm specifically talking about use cases where you cannot use Composer everywhere. WordPress is one such example, but it's far from the only legacy PHP system out there that does not use Composer itself but can be extended.
As I said, if you're working under ideal conditions and just bootstrap your entire app/site from one composer.json
file, this is a non-issue. But in that case, the above safeguards won't hurt you either.
from assert.
The !function_exists() is surely a requirement to stop attempting to duplicate the loading of functions for anyone using a polyfill. Every polyfill I've seen uses the same pattern.
from assert.
The !function_exists(...)
is used in polyfills to define functions in the global namespace while maintaining forward compatibility with newer PHP versions or extensions. Assert is not a polyfill.
from assert.
Hmm. True.
from assert.
Related Issues (20)
- Invalidly required array instead of iterable HOT 3
- date does not work with variable precision of microseconds HOT 1
- Assertion::url() does not support url with underscores in subdomains HOT 1
- Assertion::keySet
- issues with NAN HOT 3
- Assert\Assertion in annotations HOT 1
- PHP 8.0 compatibility HOT 2
- Invalid psalm annotation
- [BC break] Changes introduced in v3.2.4-v3.2.7 are excluded in v3.3.0 HOT 1
- Assertion::url validates invalid domain names HOT 1
- PHP 8 vs is_resource() HOT 1
- method greaterThan really checks greaterOrEqualThan
- `Assertion::uuid` assertion generates fatal error
- Allow predicated validation in Lazy Assertions chains
- assert/CONTRIBUTING.md on `master`
- Is there a way to assert for known specific values? HOT 1
- API to improve describing property paths
- Support to return false when an assertion fails HOT 1
- How about an assertion for array shapes?
- Assertion:date fails when matching February 29th without date
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 assert.