Skip to content

u/nikic

In this archive from Dec 2011 to Mar 2024

37
posts
1.4k
comments
3
media
12k
score

From the output logs:

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

I'd assume that's the reason.

29 points

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.

9 points

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.

22 points

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.

25 points

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.

67 points

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.

3 points

I think the primary factors here are:

  • 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.)
12 points

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.

57 points

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.

5 points

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.

24 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.