With so many parameter modes in PHP, I wanted to know exactly what ReflectionParameter
is going to return.
<?php
class Database {}
$fns = [
function ($str) {},
function ($str ="hello") {},
/** | |
* This script captures all CSS rules that are in use on the current page. | |
* | |
* - Paste the script into the browser console. | |
* - Run `collector.rules` to get a list of CSS rules in use. | |
* - As a diagnostic, run `collector.rulesWithComments` to get a list of CSS rules with comments. | |
*/ | |
var collector = (() => { | |
const rulesInUse = new Set(); |
<?php | |
class UserProvider | |
{ | |
public function __construct( | |
#[Service("user.cache-path")] | |
public readonly string $cache_path | |
) {} | |
#[Service("user.cache")] |
/* | |
I know this is probably bonkers and there must be a million reasons this wouldn't | |
actually work, but hear me out... what if variables were reactive by default?? 😏 | |
*/ | |
function fetchTodayFortune() { | |
return fetch("https://api.example.com/fortune") | |
.then((response) => response.json()) |
let animationCounter = 0; | |
export function waitForElement(selector) { | |
return new Promise((resolve) => { | |
const elem = document.querySelector(selector); | |
if (elem) { | |
resolve(elem); // already in the DOM | |
} |
With so many parameter modes in PHP, I wanted to know exactly what ReflectionParameter
is going to return.
<?php
class Database {}
$fns = [
function ($str) {},
function ($str ="hello") {},
A list of query-builders and other SQL query and/or schema abstractions.
Libraries with no activity for 2+ years will be considered "dead", as these are not keeping up with the language or ecosystem - but they may be added and may remain on the list, if they contain different or interesting ideas.
from(books).where(books.author.lower().like('%bob')
and similar.
<?php | |
use Psr\Http\Message\ResponseFactoryInterface; | |
use Psr\Http\Message\ServerRequestInterface; | |
use Psr\Http\Message\ResponseInterface; | |
use Psr\Http\Server\MiddlewareInterface; | |
use Psr\Http\Server\RequestHandlerInterface; | |
// There are essentially 3 handler/middlerware patterns: | |
// |
I was curious if we could use ChatGPT to generate a new and better manual for PHP.
This example was interesting enough that I figured it was worth posting.
It looks like ChatGPT does not know PHP 8.1 - the latest version it seems to know is PHP 8.
When asked to explain the first class Callable(...)
syntax (introduced in PHP 8.1) it does explain how to generate something that is functionally similar, using e.g. fn($car) => $car->drive()
rather than $car->drive(...)
. So it understands the concept, it just doesn't know about the new syntax.
But here's the wild part: I then proceded to explain the new syntax to it, and asked it to explain again using the new syntax - and it did it. 😮
In response to this answer:
The built-in dependency injection container does not support named dependency registrations, and there are no plans to add this at the moment.
One reason for this is that with dependency injection, there is no type-safe way to specify which kind of named instance you would want. You could surely use something like parameter attributes for constructors (or attributes on properties for property injection) but that would be a different kind of complexity that likely wouldn’t be worth it; and it certainly wouldn’t be backed by the type system, which is an important part of how dependency injection works.
I'm not sure what is meant by "type-safe" here?
The way service providers are provisioned in .NET today (via service providers and descriptors) is only "type-safe" in the sense that e.g. constructors specify the required types of dependencies that should be injected - th