I want to know what is the scope that function who is out of class. Is it private, public or protected ?
function abc {
//code here
}
class xyz {
function car () {
// code here
}
}
Now what is the abc function scop ?
Please help me
I want to know what is the scope that function who is out of class. Is it private, public or protected ?
function abc {
//code here
}
class xyz {
function car () {
// code here
}
}
Now what is the abc function scop ?
Please help me
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;
}
}
?>
functions are defined at a global level ; so, you don't need to do anything to use them from a method of your class.
For more informations, see the function page in the manual, which states (quoting) :
All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.
If a "function" is defined inside a class, it's not called a "function" anymore, even if it is still the function that is used : it is called a "method"
Methods can be used statically :
MyClass::myMethod();
Or Dynamically :
$obj = new MyClass();
$obj->myMethod();
Depending on whether they were defined as static or not.
function abc {
//code here
}
This is a public function because function scope mainly in class and in your case abc
not inside a class so it behave as a public function
public
scope to make that variable/function available from anywhere, other classes and
instances of the object.
private
scope when you want your variable/function to be visible in its own class only.
protected
scope when you want to make your variable/function visible in all classes that extend current class including the parent class.
reference What is the difference between public, private, and protected?