Jump to content

$GLOBALS? pass variable to class without passing through function par list.


Anti-Moronic

Recommended Posts

I have this variable:

 

$string = "string";

 

I want it to be accessible within my class and function:

 

class someclass{

 

function speak(){

 

echo $test;

 

}

 

}

 

Currently, I define $test as global within the func, and all is ok, I can now use it within that func. My question is, how secure is this, does this have anything to do with register_globals? Is there an alternative?

 

Remember, I can't pass these variables into the function.

 

Thanks.

Hey, I think you want something like this.

 

class fooClass {

   function speak($bar) {
      echo $bar;
   }

}

$foo_class = new fooClass;
$foo = "bar";
$foo_class->speak($foo);

 

That sends a variable from you script to the class method 'speak'. And then you do whatever you want with it.

 

Unless the string assigned to $foo is coming from a $_POST, $_GET or other request method this has nothing to do with register_globals.

 

This is not good class syntax, jsut an example.

I know, I pass variables to functions all the time. What I'm asking is, does this:

 

$test = "hello";

 

class{

 

function speak(){

 

global $test;

 

echo $test

 

}

 

}

 

...have anything to do with register_globals? By making the $test variable global?

 

Thanks.

 

Thorpe:

 

"Currently, I define $test as global within the func."

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.