I declare my class in PHP and several functions inside. I need to call one of this functions inside another function but I got the error that this function is undefined. This is what I have:
<?php
class A{
function b($msg){
return $msg;
}
function c(){
$m = b('Mesage');
echo $m;
}
}
This is basic OOP. You use the $this keyword to refer to any properties and methods of the class:
<?php
class A{
function b($msg){
return $msg;
}
function c(){
$m = $this->b('Mesage');
echo $m;
}
}
I would recommend cleaning up this code and setting the visibility of your methods (e.e. private, protected, and public)
<?php
class A{
protected function b($msg){
return $msg;
}
public function c(){
$m = $this->b('Mesage');
echo $m;
}
}
You can use class functions using $this
<?php
class A{
function b($msg){
return $msg;
}
function c(){
$m = $this->b('Mesage');
echo $m;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With