The follow error I get when I try to strtolower()
my string:
Warning: strtolower() expects parameter 1 to be string, object given in
When I do a var_dump()
it shows me the string should be a string?
string(21) "This IS a Test String"
Some code:
protected $hostname;
public function __construct($hostname)
{
//$this->hostname = $hostname;
$this->hostname = 'This IS a TeSt String';
return $this->_filter();
}
private function _filter()
{
$hostname = $this->hostname;
var_dump($hostname);
$hostname = strtolower($hostname);
$hostname = $this->_getDomain($hostname);
$hostname = $this->_stripDomain($hostname);
return $hostname;
}
Thanks in advance!
The problem is probably caused by the fact that you are trying to return
something from the constructor. You cannot do that.
You should try if this solves the problem:
public function __construct($hostname)
{
$this->hostname = $hostname;
$this->_filter();
}
Also, you seem to be doing a lot of duplicate assigning, so I would change your function to:
private function _filter()
{
var_dump($this->hostname);
$this->hostname = strtolower($this->hostname);
// here you might need other variable names, hard to tell without seeing the functions
$this->hostname = $this->_getDomain();
$this->hostname = $this->_stripDomain();
}
Note that $this->hostname
is available to all functions in your class, so you don't need to pass it as an argument.
This seems to work ok adjusted a little I think you were overwriting variables back with the intial input
<?php
class Test {
public $outputhost;
public function __construct($inputhost)
{
$this->hostname = $inputhost;
$this->outputhost = $this->_filter();
}
private function _filter()
{
var_dump($this->hostname);
$outputhost = strtolower($this->hostname);
return $outputhost;
}
}
$newTest = new Test("WWW.FCSOFTWARE.CO.UK");
echo $newTest->outputhost;
?>