• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

vars?

The Red Guy

Dork
NLC
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?
 
Well, if you wish to get something from an array in php you would do:

PHP:
echo $arrayvar[user2];

So you could do something like

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

Which could also be called as

PHP:
echo $arrayvar[0];
 
In associative arrays, always use quotes around the index

PHP:
$myarray['this']
$myarray[nothis]

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

PHP Manual: Arrays
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.
 
Take this example from IPB functions.php:
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->[b]vars[/b]['safe_mode_skins'] == 0)
		{
			// Simply require and return
			
			require $root_path."Skin/".$ibforums->skin_id."/$name.php";
			return new $name();
		}
 
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?
 
Back
Top