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.

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' ) );