passing variables into a function

Situation is like this:

$variable = "something";

function foo() {

public $variable;

echo "$variable";
}

foo();

Works everywhere in normal environment (I mean eg. PHP+Apache) but not in SC.
Why?
Should I use globals like [variable] instead?

BTW - is it efficient?
I wonder how much more memory (if so) it uses when I’m putting everything in globals.

Sorry but this code does not work everywhere as public should be global :wink: However, I consider this as bad practice for a lot of reasons. If you need to pass variables to a function then use the regular function expression as in every language:


function myfunction($vara, $varb, ...) {}

call it by using 
   $myval = myfunction(12, 3);

The global variables between [] are used to store data in a global way which is needed to pass variables between several scriptcase applications (php modules). It stores the data into a public pool. If you switch between applications the standard way (menus) then this works well. If you need to redirect it might be necessary to pass the global variables yourself like in:

[glob_myglobal]=“somevalue”;

or

sc_redir(myapp.php,glob_myglobal=“somevalue”, _parent)

In the last situation the glob_myglobal is send to the myapp where it will be accessible using []. Don’t use [] in the sc_redir macro. (bit confusing, but it’s as it is).

hope this helps.

Of course.
I made a mistake while typing here.
Instead of
public $variable;
should be
global $variable;
And this works :slight_smile: outside SC.

Concerning the rest of you answer (thank you by the way for the answer :slight_smile: ) - I just wanted to use this for the reason you mentioned - I have repeating settings I want to pass to the function.

In this particular case I wanted to use it to send system messages which have many repetitive properties (like mailserver, port, e-mail addresses etc…) and only few different like subject for example.

So instead of typing every time sc_mail_send(‘subject’,‘message’ + a lot more of stuff here); I created my own library to simplify my life so I can do something like this: my_mail_send(‘subject’,‘message’);

So I’m putting this function in any app when I need to send a system message. And it works for me.

Is that a bad idea?
My concern was is it efficient and a good idea in general. If not what would be better?