PHP - Class Inherit problem

Posted by TatMing on Stack Overflow See other posts from Stack Overflow or by TatMing
Published on 2010-04-28T14:18:03Z Indexed on 2010/04/28 14:23 UTC
Read the original article Hit count: 159

Filed under:

I have A.php and B.php

A.php

<?php
error_reporting(E_ALL);
ini_set("display_errors",1);
class myClass
{
  function hello()
  {
    return 'hello';
  }  
}
?>

B.php

<?php
error_reporting(E_ALL);
ini_set("display_errors",1);
require_once('/A.php');
$a = new myClass();
testing();

function testing()
{    
    echo $a ->hello();
}
?>

B.php inherits A.php , if i run B.php,but it show "Fatal error: Call to a member function hello() on a non-object."

So the question is simple, how can i correct this ,but "$a = new myClass();" is not inside the function, since in .NET world can do this, i believe PHP also possible.

And one more question is, what is the modify of function in A.php ,if i have not state private/public/protected???

© Stack Overflow or respective owner

Related posts about php