An Ampersand (&) before a function means? [duplicate] - php

This question already has answers here:
What does it mean to start a PHP function with an ampersand?
(3 answers)
Closed 7 years ago.
I know & is used to create references.
But I wonder what having a & before a function name means:
function &DB($params = '', $active_record_override = FALSE) { // code }

It returns the result by reference. See the manual entry for it here.

Related

What does these ... mean in this example? [duplicate]

This question already has answers here:
What is the meaning of three dots (...) in PHP?
(9 answers)
Closed 5 years ago.
I'm learning PHP http://php.net/manual/en/migration70.new-features.php and in the following example, I don't understand ... prepended with the $ints parameter in the function definition.
<?php
// Coercive mode
function sumOfInts(int ...$ints)
{
return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1));
Can anybody please tell me what those dots are for?
Thanks.
that means that when you call that function, you can pass X integers and the function will process them, doesn't matter how many are they. If you call sumOfInts(3,4,6,2,9) or sumOfInts(3,2,9), the function works, no matter how many arguments you pass

Why a function starts with # in php ? like #unpack(xxx)? [duplicate]

This question already has answers here:
What is the use of the # symbol in PHP?
(11 answers)
Closed 7 years ago.
$block_header = #unpack('Sc_size/Su_size/Lchecksum', fread($this->fp, 8));
What does this mean ?
PHP Error Control Operators.
it avoids showing the error returned by the function. more info in the link:
http://www.php.net/manual/en/language.operators.errorcontrol.php

What does prepending '&' to a function name mean in PHP? [duplicate]

This question already has answers here:
What does it mean to start a PHP function with an ampersand?
(3 answers)
Closed 7 years ago.
I'm using a CMS package written in PHP. In one of it's core files I saw following line that is for defining a function in a class body.
public static function &getLib($sClass, $aParams = array()) {
// Code
}
I didn't understand why the function name 'getLib' has been prepended with the ampersand(&) sign? I've never seen such thing before.
Can someone please explain me in detail why such thing has been done and what's the benefit it has over simply using the function name?
It means the function should return a reference to a variable rather than just the value itself.

What's "&" in front of function names? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
What does it mean to start a PHP function with an ampersand?
Reference - What does this symbol mean in PHP?
What does this signature mean(&) in PHP?
What's up with the & in front of function names? What does it do?
function &fname(){
}

php function & symbol [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What does it mean to start a PHP function with an ampersand?
hi
Why is it that some php functions have a '&' in their signature for example
function &getData()
It returns a reference to a variable.

Categories