I believe this was in part for forward compatibility with generics. Foo<Bar?> would have a closing PHP tag at the end. (The opening tag is not a problem as it's already open in this context.)
const is indeed also defined at runtime, just like define. However, it must occur at top-level scope, and the value is required to be a constant expression. These limitations are purely artificial though.
Failed loading /opt/src/php-8.1.1/lib/php/extensions/no-debug-non-zts-20200930/opcache.so: /opt/src/php-8.1.1/lib/php/extensions/no-debug-non-zts-20200930/opcache.so: cannot open shared object file: No such file or directory
Unless specified otherwise, the assumption is that the inbound and the outbound licenses are the same. That is, contributors license their contributions to the project under the same terms the project is licensed to users.
This matches my understanding as well. The PHP group does not own copyright, as this would require all contributors to sign a CLA that explicitly transfers copyright. In absence of that, contributions follow the inbound-outbound licensing principle.
My 2c on this are: The foundation is mostly about money. Funding permitting, scope could be expanded to hire someone to work on PHP infrastructure and the website.
But I don't think there's much appetite for getting involved with legalities right now. Heck, the foundation is not even set up as its own legal entity.
It's okay for users to reference issues however they like -- this only really matters to developers for references in commit messages / the NEWS file, where we otherwise have an ambiguity.
Whether something is a security issue depends on your threat model. As far as the PHP upstream project is concerned, our threat model is a remote attacker. We consider the case where the attacker has ability to execute arbitrary PHP code on the server a lost cause.
Of course, for a shared hosting provider that does not use any OS-level separation between clients, this is a security issue. As far as the PHP project is concerned, this is a fundamentally insecure deployment method. You may use it at your own risk.
This is a matter of practicality, because the PHP implementation is very far removed from reliably sandboxing arbitrary attacker-controlled code. There are some languages that have this as a hard design constraint (the most important being JavaScript), but for other scripting languages this is not a primary goal (definitely not for PHP, and I would strongly suspect not for Python or Ruby either, though I'm not sure on that count).
If we wanted to move in that direction, the first step would be to promote all remaining engine notices/warnings to exceptions, because there is a large class of interrupt vulnerabilities caused by them (to the point that addressing other issues would be somewhat "pointless" from a security perspective). One of my bigger regrets for PHP 8.0 is that we did not make undefined variables an exception.
Using single quotes unless you need to evaluate the string for variables.
Doesn't matter, probably never did.
Use static functions unless you need $this.
I don't think this matters.
Never use array_merge() inside any foreach loop.
This is actually good advice, in the sense that it can become a genuine performance problem (makes the loop quadratic). Of course, only relevant for large arrays and/or hot code.
Never use $key => &$value because $value will end pointing to the last.
This is a tricky one, because both options (by-ref iteration and by-val iteration with explicit changes via key) have their own caveats. Talking purely about performance, foreach by-ref will convert all array elements to references, which will permanently increase memory usage of the array by 32 bytes per element. By-ref also uses a less efficient iteration mechanism (a tracked array pointer). Conversely, doing a by-value foreach will fully copy the array the first time you modify it in the loop.
Never use __call() to handle dynamic calls unless necessary.
Not using magic methods where you can avoid is generally good advice independently of performance considerations... __get()/__set() carry a particularly high performance penalty. __call() since PHP 7 is a bit more efficient because it now uses a call trampoline to avoid VM reentry. Of course, it still has overhead, and the __call() implementation itself is likely going to use inefficient operations as well (like calling a method with a dynamic name).
Always type return so the interpreter doesn't guess.
This may improve performance in some cases due to type inference optimization, but may also hurt performance due to additional runtime type checks.
Just to check the obvious: Are you sure you're modifying the right ini file? It may be different between PHP CLI and PHP FPM.
After migrating from php 7.1 to 8 all response times doubled in my app and I need to improve the situation.
You're going to have better mileage figuring out what caused this with a profiler. First guess would be that your application is generating a lot of suppressed deprecation warnings.
The proposal and implementation both are incomplete with regards to reference arguments. This only came up directly before the vote was started, and the RFC author decided to specify the behavior of the implementation (references allowed), even though the implementation does not implement proper reference support beyond the most trivial case. Both allowing and forbidding references is not trivial in this context, so this question should have been resolved more comprehensively.
The pipe operator as proposed is only really nice to use in conjunction with the partial function application proposal that has been declined. The first-class callable syntax (which is likely to pass) makes the pipe operator less horrible, but also not great. There is an alternative approach to the pipe operator (https://wiki.php.net/rfc/pipe-operator) which does not require partial function application to work well, but the RFC author is fundamentally opposed to that approach.
On a more personal note, I remain unconvinced that this is a worthwhile addition to the language. While use of the functional paradigm is increasingly common in PHP, in the sense that state tends towards the immutable and APIs towards the pure, I don't think certain aspects of functional style fit in well with the language. I could really do without point-free style in PHP code. I expect that primary application of pipes would be in transformation chains on strings or arrays, which might be better approached through the "scalar objects" angle, which fits in better with modern PHP code. (Worth noting that the alternative pipe proposal from the previous point cannot be used in point-free style, but this one can.)
Not a fan of this particular bit of syntax sugar. I can see how this can be nice for something like
public function getName(): string => $this->name;
but the numerous examples in the RFC illustrate that this is going to be used and abused far beyond that. I find the examples involving match expressions in https://wiki.php.net/rfc/short-functions#match_functions particularly illustrative of how "single expression" does not imply "small".
I am still waiting for the brave champion who will fix the intellectually challenged PSR brace placement rules, which would benefit all methods, rather than just the single expression ones.
Yes, I don't believe PHP will use * for dereferenceing. My point was just that this symbol choice is completely arbitrary. A priori, there is no reason to expect that *$foo->bar has anything to do with acquiring a callable, or that $foo->bar is even a method at all in this context. (This is unlike the $foo->bar(...) syntax, which is clearly referring to a method.)
Other alternatives along the same line are ^$this->privateMethod, |$this->privateMethod, and I believe ?$this->privateMethod would also work. About any symbol that doesn't have a unary use yet would work from a technical perspective.
I'm somewhat conflicted on this. I think the ... notation actually makes a lot of sense by analogy with argument unpacking. foo(...) is basically like fn(...$args) => foo(...$args).
But I also totally see how it comes off as confusing when you see it the first time.
We also discussed some alternatives like strlen::function, but those have their own problems. E.g. based on the A::class analogy, one could expect that strlen::function is just going to return the function name (subject to name resolution) and not a callable object.
I believe this was in part for forward compatibility with generics.
Foo<Bar?>would have a closing PHP tag at the end. (The opening tag is not a problem as it's already open in this context.)Just checked the 5.6 source code, and apparently pkg-config support also existed back then: https://github.com/php/php-src/blob/05fb10165081cb4fb55a9943b44cab62c627db7a/acinclude.m4#L2335
So I would generally expect that using
--with-opensslwithout path works. What doespkg-config --modversion opensslreturn for you?constis indeed also defined at runtime, just likedefine. However, it must occur at top-level scope, and the value is required to be a constant expression. These limitations are purely artificial though.Undefined variables are also an Error exception in PHP 9 (https://wiki.php.net/rfc/undefined_variable_error_promotion).
At least currently, it's not possible to make a donation that is tied to a specific feature.
Dmitry is employed by Zend aka Rogue Wave aka Perforce to work on PHP. He's not funded by the foundation.
From the output logs:
I'd assume that's the reason.
Unless specified otherwise, the assumption is that the inbound and the outbound licenses are the same. That is, contributors license their contributions to the project under the same terms the project is licensed to users.
Thanks :)
This matches my understanding as well. The PHP group does not own copyright, as this would require all contributors to sign a CLA that explicitly transfers copyright. In absence of that, contributions follow the inbound-outbound licensing principle.
My 2c on this are: The foundation is mostly about money. Funding permitting, scope could be expanded to hire someone to work on PHP infrastructure and the website.
But I don't think there's much appetite for getting involved with legalities right now. Heck, the foundation is not even set up as its own legal entity.
It's okay for users to reference issues however they like -- this only really matters to developers for references in commit messages / the NEWS file, where we otherwise have an ambiguity.
Whether something is a security issue depends on your threat model. As far as the PHP upstream project is concerned, our threat model is a remote attacker. We consider the case where the attacker has ability to execute arbitrary PHP code on the server a lost cause.
Of course, for a shared hosting provider that does not use any OS-level separation between clients, this is a security issue. As far as the PHP project is concerned, this is a fundamentally insecure deployment method. You may use it at your own risk.
This is a matter of practicality, because the PHP implementation is very far removed from reliably sandboxing arbitrary attacker-controlled code. There are some languages that have this as a hard design constraint (the most important being JavaScript), but for other scripting languages this is not a primary goal (definitely not for PHP, and I would strongly suspect not for Python or Ruby either, though I'm not sure on that count).
If we wanted to move in that direction, the first step would be to promote all remaining engine notices/warnings to exceptions, because there is a large class of interrupt vulnerabilities caused by them (to the point that addressing other issues would be somewhat "pointless" from a security perspective). One of my bigger regrets for PHP 8.0 is that we did not make undefined variables an exception.
Right, I was thinking in terms of static methods here. Using static closures can indeed be important to prevent implicit $this capture.
Doesn't matter, probably never did.
I don't think this matters.
This is actually good advice, in the sense that it can become a genuine performance problem (makes the loop quadratic). Of course, only relevant for large arrays and/or hot code.
This is a tricky one, because both options (by-ref iteration and by-val iteration with explicit changes via key) have their own caveats. Talking purely about performance, foreach by-ref will convert all array elements to references, which will permanently increase memory usage of the array by 32 bytes per element. By-ref also uses a less efficient iteration mechanism (a tracked array pointer). Conversely, doing a by-value foreach will fully copy the array the first time you modify it in the loop.
Not using magic methods where you can avoid is generally good advice independently of performance considerations...
__get()/__set()carry a particularly high performance penalty.__call()since PHP 7 is a bit more efficient because it now uses a call trampoline to avoid VM reentry. Of course, it still has overhead, and the__call()implementation itself is likely going to use inefficient operations as well (like calling a method with a dynamic name).This may improve performance in some cases due to type inference optimization, but may also hurt performance due to additional runtime type checks.
There is actually, internal enum support has been added in https://github.com/php/php-src/pull/7302.
Just to check the obvious: Are you sure you're modifying the right ini file? It may be different between PHP CLI and PHP FPM.
You're going to have better mileage figuring out what caused this with a profiler. First guess would be that your application is generating a lot of suppressed deprecation warnings.
Not sure what you're waiting for, as
readonlyand{ get; init; }would be pretty much (exactly?) the same.I think the primary factors here are:
Generics
The former, this adds essentially no complexity to core.
Not a fan of this particular bit of syntax sugar. I can see how this can be nice for something like
but the numerous examples in the RFC illustrate that this is going to be used and abused far beyond that. I find the examples involving
matchexpressions in https://wiki.php.net/rfc/short-functions#match_functions particularly illustrative of how "single expression" does not imply "small".I am still waiting for the brave champion who will fix the intellectually challenged PSR brace placement rules, which would benefit all methods, rather than just the single expression ones.
We actually implemented
enumas a contextual keyword, to make sure all those existing enum implementation using anEnumclass keep working.Yes, I don't believe PHP will use
*for dereferenceing. My point was just that this symbol choice is completely arbitrary. A priori, there is no reason to expect that*$foo->barhas anything to do with acquiring a callable, or that$foo->baris even a method at all in this context. (This is unlike the$foo->bar(...)syntax, which is clearly referring to a method.)Other alternatives along the same line are
^$this->privateMethod,|$this->privateMethod, and I believe?$this->privateMethodwould also work. About any symbol that doesn't have a unary use yet would work from a technical perspective.I'm somewhat conflicted on this. I think the
...notation actually makes a lot of sense by analogy with argument unpacking.foo(...)is basically likefn(...$args) => foo(...$args).But I also totally see how it comes off as confusing when you see it the first time.
We also discussed some alternatives like
strlen::function, but those have their own problems. E.g. based on theA::classanalogy, one could expect thatstrlen::functionis just going to return the function name (subject to name resolution) and not a callable object.