Is there a way to use toString template in phpStorm like in InteliJ?

In my classes I need to implenet `jsonSerialize` method. I'm aware that I can't add my own code generator, but I thought that I can change velocity templates for similar method like `toString`. Both methods get class properties and build some custom output. However in phpStorm there is no such method in code templates. I found a nice plugin but it is dedicated only for InteliJ.

Is there a way to overwrite some template, which has got access to class properties or create own code generator other then writing own plugin?


Hi there,

Please clarify what exactly do you mean by "toString template"? How do you generate it?


P.S. Maybe you can just use what's already available and then use custom Live Template to quickly insert your own code..?


I was thinking about following entry: and "Generate toString()" section. In Java it will generate following method:

public String toString() { 
return "MyClass{" + "name='" + name + '\'' + ", url='" + url + '\'' + ", port=" + port + ", validIps=" + Arrays.toString(validIps) + '}';

What I need in php is almost the same implementation as toString for JAVA but for JSON representation when encoded with json_encode ->

Live Template and File Template can't do it. I need to read class properties (like generate getters and setters is doing) and then generate one method with all properties. Something like that:


public function jsonSerialize() {
return [
'id' => $this->getId(),
'objectId' => $this->getObjectId(),
'sortOrder' => $this->getSortOrder(),
'name' => $this->getName(),
'address' => $this->getAddress(),
'prices' => $this->getPrices(),
'isPermanent' => $this->getIsPermanent(),
'surface' => $this->getSurface(),
'description' => $this->getDescription(),
'isMobile' => $this->getIsMobile(),
'chartColor' => $this->getChartColor(),
'maxDiscount' => $this->getMaxDiscount(),
'showPriceDiscount' => $this->getShowPriceDiscount(),
'isAvailableForMobile' => $this->getIsAvailableForMobile(),
'floor' => $this->getFloor(),
'features' => $this->getFeatures(),
'additionalTimeBeforeReservation' => $this->getAdditionalTimeBeforeReservation(),
'additionalTimeAfterReservation' => $this->getAdditionalTimeAfterReservation(),
'isBookingAvailableForClient' => $this->getIsBookingAvailableForClient(),
'connectedRoomId' => $this->getConnectedRoomId(),
'evaluations' => $this->getEvaluations(),
'isAvailableForDistributor' => $this->getIsAvailableForDistributor(),
'reservationLimits' => $this->getReservationLimits(),
'isModule' => $this->getIsModule(),
'moduleGroupId' => $this->getModuleGroupId(),
'canSubmitRequestIfUnconfirmed' => $this->getCanSubmitRequestIfUnconfirmed(),
'typeId' => $this->getTypeId(),
'images' => $this->getImages(),


Hi, I also looking for a way to generate the __toString() php method with my serialized object.

Exactly what IntelliJ does with a Java object.

If there is a feature to vote or a dedicated plugin, thanks to share.


Thanks for creating a feature request. If anyone is interested here's a link to it:


+1 jsonSerialize generator will totally be helpful!


Please sign in to leave a comment.