Jump to content

Please, don't convert $table to a string

Ilya Hoilik

Recommended Posts


What's a reason to convert \IPS\Helpers\Table to a string? In some places I see something like this:

\IPS\Output::i()->output = (string) $table;

/* or */

\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'group' )->template( (string) $table );

Can you please avoid converting to a string? It will allow us to hook into a method and change something in the table without touching original code. So, for example, let's test this code:


When you convert $table to a string we can do nothing with it:


When you don't convert it, then we can easy change something we need:


In the second case we stay original code untouched, that is better than replacing a whole method.

Link to comment
Share on other sites

in your second example:

\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'group' )->template( (string) $table );

printing/echoing of \IPS\Output::i()->output will return a string any way, even if $table wasn't being casted to a string, cause the template would've done that if they did {$table|raw} inside the template. however your first one, i could see there isn't a need to cast to string.

however, i would ask, is there no other way to hook into what you need, before that point?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...