Skip to content

Instantly share code, notes, and snippets.

@meglio
Created May 28, 2020 14:09
Show Gist options
  • Save meglio/fdf94a5cb17945713f453946011f0af8 to your computer and use it in GitHub Desktop.
Save meglio/fdf94a5cb17945713f453946011f0af8 to your computer and use it in GitHub Desktop.
<?php
/******** TEST 1 ********/
// SELECT * FROM email WHERE id = 100
$fetched = [
'id' => 100,
'subject' => 'Welcome!'
];
$row = new class($fetched) extends Row { public EmailColumns $email; };
echo "TEST 1: " . $row->email->id . ': ' . $row->email->subject . "\n"; // 100: Welcome!
/******** TEST 2 ********/
// SELECT e_id, e_subject FROM email e WHERE id = 100
$fetched = [
'e_id' => 100,
'e_subject' => 'Welcome!'
];
$row = new class($fetched) extends Row { public EmailColumns $e; };
echo "TEST 2: " . $row->e->id . ': ' . $row->e->subject . "\n"; // 100: Welcome!
/******** TEST 3 ********/
// SELECT e1.*, e2.* FROM email e1 LEFT JOIN email e2 ON ... e WHERE e1.id = 100
$fetched = [
'e1.id' => 100,
'e1.subject' => 'Welcome 100!',
'e2.id' => 200,
'e2.subject' => 'Welcome 200!',
];
$row = new class($fetched) extends Row {
public EmailColumns $e1;
public EmailColumns $e2;
};
echo "TEST 3: " . $row->e1->id . ': ' . $row->e1->subject . "\n" // 100: Welcome 100!
. "\t" . $row->e2->id . ': ' . $row->e2->subject . "\n"; // 200: Welcome 200!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment