PHP

timwolla, in How the PHP community add features to the language itself
@timwolla@phpc.social avatar

@symfonystation The information in the article are pretty outdated and/or incorrect. The linked bug tracker is no longer in use, the 50%+1 majority no longer exists. The linked example RFCs are not a good representation and two of them are not implemented or even voted on, despite the article claiming the the listed RFCs have been "implemented over the years". Based on the “Certification” link at the end, I suspect that this is pure SEO spam.

kvothe, in TIL kbin's backend is written in PHP (Symfony, Doctrine)

Yeah, found out yesterday.

Apparently ActivityPub has very solid support on PHP. Couldn't find anything on other languages tho.

grmpyprogrammer, in Unit testing tips by examples in PHP

Thanks for organizing all your thoughts in one spot.

rikudou, in Design Patterns in PHP 8: Builder

Practical example I have written: github.com/Unleash/…/UnleashBuilder.php

abhibeckert, in Design Patterns in PHP 8: Builder

You’ve missed out on the biggest feature in PHP 8. With named arguments it’s now possible for arguments to be provided in any order. You can now have functions with a large number of optional parameters, without creating a total shit show.

Instead of writing this:

<pre style="background-color:#ffffff;">
<span style="color:#323232;">$product = $productBuilder
</span><span style="color:#323232;">    ->setId(101)
</span><span style="color:#323232;">    ->setName('iPhone 13')
</span><span style="color:#323232;">    ->setPrice(999.99)
</span><span style="color:#323232;">    ->setDescription('New iPhone 13 with A15 Bionic chip')
</span><span style="color:#323232;">    ->setManufacturer('Apple Inc.')
</span><span style="color:#323232;">    ->setInventory(1000)
</span><span style="color:#323232;">    ->setDiscount(10)
</span><span style="color:#323232;">    ->build();
</span>

You can now do this:

<pre style="background-color:#ffffff;">
<span style="color:#323232;">$product = $productBuilder->set(
</span><span style="color:#323232;">    id: 101,
</span><span style="color:#323232;">    name: 'iPhone 13',
</span><span style="color:#323232;">    price: 999.99,
</span><span style="color:#323232;">    description: 'New iPhone 13 with A15 Bionic chip',
</span><span style="color:#323232;">    manufacturer: 'Apple Inc.',
</span><span style="color:#323232;">    inventory: 1000,
</span><span style="color:#323232;">    discount: 10
</span><span style="color:#323232;">)->build();
</span>
premavansmuuf, in Design Patterns in PHP 8: Builder

Sadly, no explanation whatsoever of why this approach might be better than just building the object yourself. The example provided is fairly trivial and doesn’t seem to justify using a builder.

Also, how would you do validation of properties (or even detect incompatibility of some of them)? Surely, because Product can be created directly, the Product class itself should validate its values. But it also makes sense for the ProductBuilder to have its own validation, right? Would that mean doing the validation twice?

The article tries to sell the pattern as being your best friend, but at the same time doesn’t say how that’s gonna happen.

abhibeckert, (edited )

The main advantage of a builder is you can create an object in multiple steps instead of one step.

During the builder process the object might temporarily be in an invalid state - for example perhaps you can’t easily access the product price. You wouldn’t want price to be an optional value for the actual product class, but it can be optional for the builder (as long as it’s set once build() is called).

kglitch, in How to Store Images in SQLite with PHP

Never do this if you expect to have a decent amount of traffic/users as performance will be terrible.

Downcount, in Why use declare(strict_types=1) in PHP - Fast tips

Furthermore working with HTTP requests can be frustrating with strict typing enabled, since in HTTP requests everything is a string.

Sending the payload as JSON and you can be (quite) strict again.

grandel, in Why use declare(strict_types=1) in PHP - Fast tips

Is this still necessary with php 8+? With all the type hinting and so on?

abhibeckert, (edited )

Is it necessary? No. It never was. But it is recommended.

Consider this code:


<span style="color:#323232;">function add(int $a, int $b) { return $a + $b; }
</span><span style="color:#323232;">
</span><span style="color:#323232;">$result = add(5, '10');
</span>

In strict_types mode, passing a string will throw an exception. In the default mode (including in PHP 8), the string will be silently cast to an integer.

Here’s a more realistic example:


<span style="color:#323232;">$result = add($_POST['a'], $_POST['b']);
</span>

HTTP values are always strings. So that code will only work with strict types disabled… and there is a lot of PHP code in the world that relies on this arguably “bad” behaviour.

I’d bet one day strict types be enabled by default. So if you want your code to be future proof… get used to enabling it now for all new files. Also I agree with @Dwoncount - you should really be using JSON instead of $_POST. And your JSON should have integer values, not strings.

Danakin, in PHP 8.3 Released

Pretty happy with a smaller incremental release. The only feature I see myself using immediately will probably be typed constants, but I like the datetime exceptions and json_validate as well.

ernest, in Code quality tool PHP_CodeSniffer has a new maintainer but needs corporate support
ernest avatar
abhibeckert, in What’s new in PHP 8.4

Seems like a pretty modest release, other than the new JIT.

godlike, in DepScan ❤️ PHP
@godlike@phpc.social avatar

@symfonystation The real issue here is that too many PHP applications are not configured to work with a single PHP entrypoint, instead, they enable any dot php file to be served. This is criminal often, specially on nginx where you can't ship these rules like Apache (an .htaccess file on web root) and users share their own rules without realizing the hazardous conditions.

64bithero, in Why PHP continues to be a popular but divisive programming language
@64bithero@mstdn.games avatar

@symfonystation I love using the language and I’m tired of people claiming it’s obsolete and not useful. Not everything needs to be c-sharp or rust

oliver, in Never write another loop again
@oliver@phpc.social avatar

@symfonystation I don't get it, are loops now evil? Why would one want to not use them? Stuffing arrays into collections in order to manipulate them "nicely" is not a crime, sure. I just have a problem understanding why the other way is presented as bad/no-no.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • kavyap
  • InstantRegret
  • ethstaker
  • DreamBathrooms
  • mdbf
  • magazineikmin
  • thenastyranch
  • Youngstown
  • tacticalgear
  • slotface
  • Durango
  • khanakhh
  • rosin
  • everett
  • Leos
  • vwfavf
  • normalnudes
  • osvaldo12
  • cubers
  • GTA5RPClips
  • cisconetworking
  • ngwrru68w68
  • anitta
  • provamag3
  • tester
  • modclub
  • megavids
  • JUstTest
  • All magazines