If I define a class LOG
like this:
class LOG {
static public function LOG(){
return;
}
}
echo 1;
When I run it, it shows nothing. If I comment out the method like this:
class LOG {
/*static public function LOG(){
return;
}*/
}
echo 1;
It will show "1" in browser. Why doesn't the first code snippet work?
When you turn error reporting on, you'll get this error:
Fatal error: Constructor LOG::LOG() cannot be static
Removing the static
keyword in front of the function will work:
class LOG{
public function LOG(){
return;
}
}
In PHP, when you create a class like this:
class LOG{
static public function LOG(){
return;
}
}
(With the same named function as the class)
It will run that function as the __construct()
method. It doesn't reach the echo because of the return;
statement you have in there.
If you comment it out, it should work:
class LOG{
static public function LOG(){
// return;
echo 'inside class';
}
}
But I don't think that's the error, there has to be something else. Turn on error reporting and let us know if there are any errors.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments