General Community > Scripting Help
defining a function
Aquilo:
I was wondering if this was a good way to call functions as you would variables, this works but under windows it returns an error thats why I used the @ with define I was just wondering if it was recommended or caused issues in scripts.
--- Code: ---<?php
@define(BAR, foo());
echo BAR;
function foo(){
return 'foo bar';
}
?>
--- End code ---
[Unknown]:
I can't believe that works like that.
-[Unknown]
Parham:
wait, i don't get it... why is that at all weird?
I mean if you can do this:
--- Code: ---$variable = foo();
print $variable;
function foo(){
return 'foo bar';
}
--- End code ---
why can't you define constants in the same way?
[Unknown]:
I thought this was bad though!
$variable = foo();
I thought you had to do:
$variable = 'foo';
And then:
$variable();
-[Unknown]
Parham:
oh wait, nevermind, i read the example wrong... that's pretty cool. It doesn't define the constant as the function though (at least i think not), it processes the function and gets the return statement on the "define" line.
Navigation
[0] Message Index
[#] Next page
Go to full version