TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

v 3.9.0 new magic method __toString()

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: TomH
Date: 2014-02-03
Time: 06:10

v 3.9.0 new magic method __toString()

You mention that we can now merge DateTime objects (also objects) with the magic method __toString()

Since I am not a programmer who understands objects or methods - could you someday make an example of how to use the magic method __toString() to merge a DateTime object ?
- and what is a DateTime object ?
- and where does the DateTime object come from ?

Thanks for TBS every day (any bloke like me can do a lot of what a real programmer just does by using TBS),
By: Skrol29
Date: 2014-02-03
Time: 10:50

Re: v 3.9.0 new magic method __toString()

Hi TomH,

It is mentioned that TBS "now can merge DateTime objects and also objects with the magic method __toString().".

But DateTime doesn't have a magic method __toString(). At least we cannot say if it has one.

DateTime is an internal PHP class provided since version 5. It enables you manage dates and times values with objects in one hand, and to expend the support of dates and times in another hand. For example, it can manage dates before 01/01/1970, that was not possible with simple date/time functions before.

__toString() is a magic method for PHP class. If you create your own class, and if you add to this class a method (i.e. a function) named __toString(), then this method will be automatically invoked when the code tries to implicitly convert the object to a string. For example, when you code:
$str = (string) $myObj;
$str = 'ok' . $myObj;