Objects as Strings

There is now a special method __toString() that can be used to allow objects to be safely used as strings.

class foo {
    public $vals = array('foo', 'bar', 'baz');

    function __toString()
        return implode(' ', $this->vals);

$a = new foo();
echo $a; // will print "foo bar baz"

Loading ...

Related Results :

  1. Objects as Strings
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author