PHP Tutorial - PHP strval() function






Get the string value of a variable.

Syntax

PHP strval() function has the following syntax.

string strval ( mixed $var )

Parameter

  • var - The variable that is being converted to a string.

Return

The string value of var.

Example

Convert class to a string


<?php/* ww  w.j a  v  a 2  s  . c  o m*/
class StrValTest
{
    public function __toString()
    {
        return __CLASS__;
    }
}

// Prints 'StrValTest'
echo strval(new StrValTest);
?>

The code above generates the following result.