The function should not return anything ... If you look at the C (++) function, many of them are not (well, not explicitly):
void nonReturningFunction(const int *someParam);
int main()
{
int i = 12;
nonReturningFunction(&i);
return 0;
}
void nonReturningFunction(const int *someParam)
{
printf("I print the value of a parameter: %d",someParam);
}
The latter returns nothing, well, it returns the void. The main function returns something: 0it is usually a signal to the system so that it knows that the program is finished and it ended well.
PHP . , , -. , .
, :
<?php
class Foo
{
private $foo,$bar;
public function __construct()
{
$this->foo = 'bar';
}
public function getFoo()
{
return $this->foo;
}
public function getBar()
{
return $this->foo;
}
public function setBar($val = null)
{
$this->bar = $val;
return $this;
}
public function setFoo($val = null)
{
$this->foo = $val;
return $this;
}
}
$f = new Foo();
$f->setFoo('foo')->setBar('bar');
echo $f->getFoo();
?>
setter , :
$f->setFoo('foo');
$f->setBar('Bar');
, . , :
function manipulateArray(array &$arr)//<-- pass by reference
{
sort($arr);
}
$arr = range('Z','A');
manipulateArray($arr);
var_dump($arr);
:
function manipulateArray(array $arr)//<-- pass by copy
{
sort($arr);
return $arr;
}
$arr = range('Z','A');
manipulateArray($arr);
var_dump($arr);
$arr = manipulateArray($arr);
, . , , . , , .