Answer the question
In order to leave comments, you need to log in
Calling a non-existent method?
In OOP, you need to implement data acquisition for a number of predefined tables from the database. Is there a better solution than __callStatic?
An example of what's available so far:
class Field {
public static function __callStatic( string $name, array $args ) {
// здесь MySQL запрос типа (для иллюстрации поведения)
return SELECT * FROM {$name}fields WHERE id = $args['0'] AND name = $args['1']
}
}
echo Field::post( [ 2, 'meta_field' ] );
echo Field::post( 2, 'meta_field' );
echo Field::post( 2 )->meta_field;
Answer the question
In order to leave comments, you need to log in
You don't need to pass anything "as an array", the php engine will do it by itself if it doesn't find an existing method.
https://ideone.com/EsnAEZ
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question