-2

please help me with this example.. I want to call the function inside the class..

FUNCTION

class myTest(){
       function Me(){
       $x = 2;
       }
}

is this the answer?

$myval = new myTest();
echo $myval;

thank you

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
Krishna
  • 157
  • 3
  • 3
  • 11

2 Answers2

5

You need to first instantiate a new object of type 'myTest' like so:

$myObj = new myTest;

And then you can use the function like so:

$myObj->Me();

Note that at present, the function returns nothing so you'll get a 'blank screen'.

If you changed your function to read:

return "Hello";

Then you would get 'Hello' printed on screen by using the above.

I hope that helps?

H2ONOCK
  • 956
  • 1
  • 5
  • 19
0

$myval = new myTest(); here $myval is object of the your Class .

You can call the inside function with just $myval->Me();

웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
vijaykumar
  • 4,658
  • 6
  • 37
  • 54