Accessing variables and methods outside of class definitions

functions outside any class are global an can be called from anywhere. The same with variables.. just remember to use the global for the variables…

e.g

<?php
function abc() {  }

$foo = 'bar';

class SomeClass {  
 public function tada(){
     global $foo;

     abc();
     echo 'foo and '.$foo;
 }
}
?>

Leave a Comment