<?php
// Hello!
// Here's our code from the other day.
// We started with an array and converted it to an object to see how
// objects, types and an IDE/editor can help us.
// I wanted to point out some stuff about MY IDE, which is PHPStorm.
// It has a built-in understanding of PHP code and can provide lots of help.
// I don't use it all the time. It can be slow and clumsy. But for bigger projects
// it's better.
// Here's some quirks though.
// Remember we had to add strict types to get that help with the types of
// the object properties?
// We can turn this on for all files if we want it.
// Let's see if I can find that in the settings.
// Great - now we can remove the strict types declaration and still have type
// checking.
// That might get annoying. But it's an option if you want it.
// A quicker way is to search the settings. But you have to know what you are looking
// for.
// I'll show you another quirk tomorrow!
// Have a nice day!!
class Post {
// Each post has a publicly accessible ID and title
public int $id = 0;
public string $title = '';
// We will set these for each thing
}
$posts = [];
$posts[0] = new Post();
$posts[0]->id = '123'; // <- like this!
$posts[0]->title = 'Hello World';
$posts[1] = new Post();
$posts[1]->id = '456';
$posts[1]->title = 'Hello again';