Skip to content

Instantly share code, notes, and snippets.

@technosailor
Last active September 22, 2025 15:23
Show Gist options
  • Save technosailor/597b0b54b77eb6503ab1ef66b09dee7f to your computer and use it in GitHub Desktop.
Save technosailor/597b0b54b77eb6503ab1ef66b09dee7f to your computer and use it in GitHub Desktop.
Don't use arrays ad hoc
// Do NOT do this
$animals = [
'cat',
'dog',
null,
2
]:
// DO do this
class Animal
{
public string $name;
public string $species;
public function __construct( string $name, string $species )
{
$this->name = $name;
$this->species = $species;
}
}
$animals = [
new Animal( "Leo", "Lion" ),
new Animal( "Milo", "Cat" ),
new Animal( "Bella", "Dog" )
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment