Hi,
is it possible to attach or call a function that is not part of a class inside that class? If yes, how can we do this?
turb
Hi,
is it possible to attach or call a function that is not part of a class inside that class? If yes, how can we do this?
turb
Is the function being called really a method in another class?
Well, for example…
class {
.
.
.
return fFormat($this->name);
}
function fFormat($value)
{
.
.
.
}
Do you mean like this?
function outer($text){
return $text;
}
class Demo{
function __construct(){
echo outer("Hello");
}
}
$obj = new Demo();
It prints the text “Hello”.
exact … but it doesn’t seem to work!
ok it work now! Have misspelling a variable … start to be late here!
Thank you very much!
My code is working fine under PHP 5. Did you try to use my code in your system? May we see your code please?
In OOP, you access functions from outside of the class by simply refencing them by their name.
You access the functions from within the class by preceding it with $this->.
For example:
class someClass{
function __construct($var){
$this->insidefunction($var); // note the "$this->" to access inside functions
outsidefunction($var); // no "$this->" - function is outside class
}
function insidefunction($var){
echo $var;
}
}
function outsidefunction($var){
echo $var;
}