Reputation:
I have problem with PHP class and function.
My class file is:
<?php
class EF_IP{
public function ip_adresa(){
// dobivanje IP adrese
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
return $ip;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
return $ip;
} else {
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
}
}
?>
And i call from other PHP file:
EF_IP::ip_adresa();
echo $ip;
And i get error:
Strict Standards: Non-static method EF_IP::ip_adresa() should not be called statically
What i need to do?
Upvotes: 1
Views: 85
Reputation: 482
You can either make your function STATIC or instantiate the class first:
class MyClass {
public static function SomeFunction() {}
public function someOtherFunction() {}
}
Then you call either like so:
MyClass::SomeFunction()
$class = new MyClass();
$class->someOtherFunction();
Upvotes: 2
Reputation: 893
Call your function not staticly:
$ef_ip = new EF_IP();
$ip = $ef_ip->ip_adresa();
echo $ip;
or you make your function static:
public static function ip_adresa(){
// your code
}
Upvotes: 1