Last active
September 22, 2025 15:23
-
-
Save technosailor/597b0b54b77eb6503ab1ef66b09dee7f to your computer and use it in GitHub Desktop.
Don't use arrays ad hoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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