pcw Posted February 18, 2009 Share Posted February 18, 2009 Hi, I am using this section of a PERL script as an example: my ($action, $return) = @_; my $out; I know that 'my' declares the listed variables to be local (lexically) amd was wondering if there was an equivalent to 'my' in PHP. Any help would be much appreciated Link to comment https://forums.phpfreaks.com/topic/145731-does-php-have-a-my-equivalent/ Share on other sites More sharing options...
gizmola Posted February 18, 2009 Share Posted February 18, 2009 First off PHP has page scope. That is to say that scripts run, variables are created and when the script finishes everything is disposed of. Inside a script you can have functions and classes defined. All variables inside a function or class have local scope. Additionally variables declared in page scope (globally) are not visible inside class methods or functions. To use a global you would have to actually declare it as such inside a function, which would then allow the function to access the global variable's value. Link to comment https://forums.phpfreaks.com/topic/145731-does-php-have-a-my-equivalent/#findComment-765133 Share on other sites More sharing options...
pcw Posted February 18, 2009 Author Share Posted February 18, 2009 Thats great, thanks for your help :-) Link to comment https://forums.phpfreaks.com/topic/145731-does-php-have-a-my-equivalent/#findComment-765164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.