New core function xp::stringOf()

at 2004-11-10 in Announcements by friebe (0 comments)

A new core function xp::stringOf() was added. It returns a string representation of the given argument. If the given argument extends lang.Object, its toString() method will be called, otherwhise the function will return the output of var_export().

This function also prevents fatal errors of the form "call to a member function of a non-object". Imagine something like this:

function getObjectById($id) { return $id ? new SomeObject() : NULL; }


To "see" what getObjectById() is returning, one would have to use code such as:

is_a($r, 'Object') ? $r->toString() : var_export($r, TRUE)


because simply calling

$r->toString()


could raise the afforementioned fatal error. The news syntax is short and convenient:

xp::stringOf($r);



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases
5.8-SERIES
Unicode
Language
5.9-SERIES

Related

Find related articles by a search for «New».