私はこのようなことをしたい:
class StrangeClass {
public function somethingLikeAMethod($var) {
/* ... */
}
public function awesomeTest() {
/* ... */
}
}
$obj = new StrangeClass;
$ex1 = $obj->somethingLikeAMethod(1);
$ex2 = $obj->somethingLikeAMethod(2);
$ex1 -> awesomeTest(); // This will output "1"
$ex2 -> awesomeTest(); // This will output "2"
つまり、そのオブジェクトの動作を変更してほしいのです。
Lua言語では、「metatables」を使用してこれを作成できますが、OO-PHPでこれを作成する方法がわかりません。ありがとうございました。
追加した:
私はLuaでこのようなことをしました:
local query = Database.query(...) -- now this variable has a query id
local query2 = Database.query(...) -- this is a other query id
local result = query.fetchAssoc() -- read below
local result2 = query.fetchAssoc() -- I called the same object with same method twice, but it will return other results
追加#2:
私がやりたいこと:
$db = new Database();
$firstResult = $db->query('SELECT * FROM `table`')->fetch_assoc();
$firstExample = $db->query("SELECT * FROM `table` WHERE `id` = '1'");
$secondExample = $db->query("SELECT * FROM `table` WHERE `id` = '2'");
$secondResult = $firstExample -> fetch_assoc();
$thirdResult = $secondExample -> fetch_assoc();