PDA

View Full Version : vars?



The Red Guy
June 19th, 2003, 08:22
Ok I might sound stupid or something, I just don't understand what's "vars" in something like $variable->vars['number']. Also, is the ' ' needed for arrays? Does this $variable->vars[number] do as well?

MN-Carl
June 19th, 2003, 16:30
Well, if you wish to get something from an array in php you would do:



echo $arrayvar[user2];


So you could do something like



$arrayvar = array (
"user2" => "blogger"
);


Which could also be called as



echo $arrayvar[0];

Cagez
June 19th, 2003, 16:55
In associative arrays, always use quotes around the index


$myarray['this']
$myarray[nothis]

Without the quotes will still work, but you just shouldnt do it.


PHP Manual: Arrays (http://ca2.php.net/manual/en/language.types.array.php)
This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string ('bar' - notice the quotes), and PHP may in future define constants which, unfortunately for your code, have the same name. It works, because the undefined constant gets converted to a string of the same name automatically for backward compatibility reasons.

The Red Guy
June 19th, 2003, 22:36
Which means it applies to classes as well, but what's the difference between vars and var?

Cagez
June 19th, 2003, 22:39
I'm not sure what you mean..?

vars has an 's' at the end? :confused:

The Red Guy
June 24th, 2003, 09:57
Take this example from IPB functions.php:

/*-------------------------------------------------------------------------*/
//
// Load a template file from DB or from PHP file
//
/*-------------------------------------------------------------------------*/

function load_template( $name, $id='' )
{
global $ibforums, $DB, $root_path;

$tags = 1;

if ($ibforums->vars['safe_mode_skins'] == 0)
{
// Simply require and return

require $root_path."Skin/".$ibforums->skin_id."/$name.php";
return new $name();
}

Cagez
June 27th, 2003, 12:59
Ah, because iPB is using classes, little Matt there has created a variable in a class called 'vars'. To access that variable, he had to make an instance of the object (class) which he named $ibforums. You access class vars by a pointer, and thus $ibforums->vars is there :)

Did that explain?

The Red Guy
July 3rd, 2003, 09:40
Which means $vars is under $ibforums?

Cagez
July 3rd, 2003, 11:22
Yep