2

I am fairly new to PHP. And I really don't understand why I can not call a function.

class test {

    public function sayHi($name, $age)
    {
        echo $name . $age;
    }
}

When trying to call sayHi it does not show up.

Thank you for any input

YakovL
  • 7,557
  • 12
  • 62
  • 102
Robertme
  • 341
  • 2
  • 4
  • 16

2 Answers2

6

Basically you are creating a function inside a class 'test', so you have to call it via a class object. example:

$testObj = new test();
$testObj->sayHi("Jon", 43);
noman tufail
  • 341
  • 2
  • 8
1
class test {

public function sayHi($name, $age)
 {
 echo $name . $age;
 }
}

$testObject = new test();

$testObject->newTest();

$testObject->sayHi("Name",23);

Copying from : Calling a function within a Class method?

Nims Patel
  • 1,048
  • 9
  • 19