Some notes on features in Modern PHP.
Tag Archives: php
Arrays in PHP
Some notes about arrays in PHP over here: PHP: Frankenstein arrays. I was already aware of most of that but I thought the notes at the bottom about supporting JSON were handy:
If you want to enforce an array to encode to a JSON list (all array keys will be discarded), use:
json_encode(array_values($array));
And if you want to enforce an array to encode to a JSON object, use:
json_encode((object)$array);
Also array_is_list is available as of PHP 8.1.
PDOStatement::fetchAll()
I’m reading the source code for PDOStatement::fetchAll().
sizeof PHP data structures zval and zend_value
sizeof( zval ) == 16; sizeof( zend_value ) == 8;
PHP 8.0
PHP 8.0 release notes: PHP 8.0
PHP type comparison tables and tokens
This is handy: PHP type comparison tables.
And this is interesting: List of Parser Tokens.
How to compile PHP from Source
Complete guide to FFI in PHP
Bumped into: Complete guide to FFI in PHP.
The relevance of PHP
Seen today: Yes, PHP is Worth Learning/Using in $CURRENT_YEAR. There’s some good discussion on some of the more recent PHP language features and other notes about what’s available in the broader ecosystem.
Factory specialization
I just knocked this up to confirm my thinking was right:
<?php class StdFeature { } class AppFeature extends StdFeature { } class FactoryBase { public function new_feature() : StdFeature { return new StdFeature; } } class Factory extends FactoryBase { public function new_feature() : AppFeature { return new AppFeature; } } $factory = new Factory(); $feature = $factory->new_feature(); assert( is_a( $feature, 'AppFeature' ) );