Reputation: 328
<?php
class a {
function fn () {
echo "My name here";
}
}
a::fn();
?>
I used scope resolution operator to check how it works, it gave no error when i checked in browser it printed correctly.
But same code when I run nusphere PhpEd debugger tool it gave me error like
Strict Standards: Non-static method a::fn() should not be called statically in D:\Program_Files\wamp\www\test\index.php on line 12 My name here
but it printed the results correctly. May i know what actuall problem is , I am new to PHP classes.I tried in google but i didn't get the reason.
Advance Thanks
Upvotes: 1
Views: 335
Reputation: 42537
The error you're seeing is E_STRICT
, which may not be displayed on your server. If you set error_reporting(E_ALL | E_STRICT)
you'll probably see that error.
The reason you're seeing the error is that the function fn
is not declared static, so you can't necessarily call it statically (like a::fn()
). You would call a non-static method like this:
$a = new a();
$a->fn();
To make your function static, change the method declaration:
public static function fn() {
// ...
}
EDIT: This manual page shows an example similar to yours above.
Upvotes: 3
Reputation: 2289
do you need to call it as a static menthod? why not try:
$a = new a();
$a->fn();
this should work ^^
Upvotes: 1