I can use traits anymore because methods have the same name, so How could I achieve this ?
do you mean ' I can't'?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i'm building a wrapper around an accountant API, I'd like to make it easy to use. With this I can manage customers and invoices / quotes....
Right now my API works like this
$api = new MyApi('my_token');
$customers = $api->getAllCustomers();
$customer = $api->getCustomer(14444);
$invoices = $api->getAllInvoices();
$invoice = $api->getInvoice(145);
There are a lot more methods by the way.
To do this, I have a main class Api.php that uses multiple traits (Customers, Invoices, ....) so all the customers logic is inside a file, the same for invoices....
First of all, are the trait good in this case ?
What I'd really want is to use my API like this:
$api = new Api('my_token');
$customers = $api->customers()->list();
$customer = $api->customer()->get(14444);
$invoices = $api->invoices()->list();
$invoice = $api->invoices()->get(145);
I can't use traits anymore because methods have the same name, so How could I achieve this ?
If you have any links that point to a tutorial or some examples, I'd take it.
Thank you
Please or to participate in this conversation.