I need to transform to uppercase a string setted by dynamic __set constructor of my PHP class. Just like JavaScript .toUpperCase() function.
Exemple:
$myObject = new Post();
$myObject->fooVar = 'Upper Case Test';
$myObject->fooVar->toUpperCase();
echo $myObject->fooVar;
Need to output: UPPER CASE TEST
This is my actual class code:
class Post {
private $data;
public function __construct()
{
echo 'Class "'. __CLASS__. '" started!'; // constructor debug
}
public function __destruct()
{
echo 'Class "'. __CLASS__. '" destroyed.'; // constructor debug
}
public function __get($varName)
{
if (!array_key_exists($varName, $this->data))
{
//this attribute is not defined!
$this->data[$varName] = 'ERROR!';
return $this->data[$varName];
}
else
{
return $this->data[$varName];
}
}
public function __set($varName, $value)
{
$this->data[$varName] = $value;
}
public function toUpper($object){
$object = strtoupper($object);
return $object;
}
}
Is this possible?
Thanks for all,