This question already has answers here:
Can I create a PHP function that I can call without parentheses?
(6 answers)
Closed 6 years ago.
all php functions need () in the end. However, exit doesnt need that.
Can I create a function manually, which I can later execute without () ?
Even more, If I have full access to php installation?
p.s. please dont tell me answers "exit is not function" or etc (My question is not if "exit" is function or not). I want to know HOW TO ACHIEVE like that.
No you can't. You have to edit Base of PHP language to accomplish this.
exit , echo , print and etc are not function .
Related
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
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.
This question already has answers here:
Does function definition order matter?
(7 answers)
Closed 1 year ago.
The following code runs in PHP
<?php
$foo = "Chocolate milkshake";
go($foo);
function go($param) {
echo $param;
}
?>
// Output: chocolate milkshake
See this Demo http://codepad.viper-7.com/ToApZa
This code runs without errors and prints specified output, why?
I thought this "function hoisting" only occurred in JavaScript
It doesn't matter where you declare your functions in PHP in most cases, as you've just proved :)
Take a look at this page for more details. The key point:
Functions need not be defined before they are referenced, except when a function is conditionally defined as shown in the two examples below.
This question already has answers here:
How do you use PHPUnit to test a function if that function is supposed to kill PHP?
(6 answers)
Closed 9 years ago.
I have a method like this:
public function xy()
{
die('script was terminated.')
}
If it possible to test this method with phpUnit?
This is possible by overloading the die() function. How you do this is described here:
Intercepting the Exit Statement
Simply calling it is not possible as there is only one PHPUnit process and you will kill it by calling die() or exit().
Also have look at the answers to this question:
How do you use PHPUnit to test a function if that function is supposed to kill PHP?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to find out where a function is defined?
in a client's website I have a php code:
return userHasActivePurchase($iId);
The website is full of icludes, requires.
I have made a full text search on "userHasActivePurchase" to find out what php file does contain this function without success.
My question is : I have a function name and I would like to know what php files contains that function.
I tried with:
print_r(userHasActivePurchase);
without success.
Please help !
As per this stackoverflow thread:
$reflFunc = new ReflectionFunction('function_name');
echo $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
You can search for text "function userHasActivePurchase" in the whole code base using grep command or by any editor's native search in directory function.
If you find this function defined at more than one place you can recognize it by putting a statement inside the function in all the files
echo __FILE__
get a decent ide (phpstorm, eclipse pdt) which will allow you to follow code - or even worst case allow you to search an entire project for a given term.