Created
May 28, 2020 14:09
-
-
Save meglio/fdf94a5cb17945713f453946011f0af8 to your computer and use it in GitHub Desktop.
This file contains 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
<?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