PHP には比較的慣れていませんが、強力なツールであることに気付きました。ここで私の無知を許してください。
デフォルトの機能を持つ一連のオブジェクトを作成したいと考えています。
したがって、クラスで関数を呼び出すのではなく、クラス/オブジェクト変数を出力するだけで、デフォルト関数、つまり toString() メソッドを実行できます。
質問: クラスでデフォルト関数を定義する方法はありますか?
例
class String {
public function __construct() { }
//This I want to be the default function
public function toString() { }
}
使用法
$str = new String(...);
print($str); //executes toString()