I have the following code in PHP. Testing in Phpunit and Laravel. Why is class method the same as instance method? I was expecting calling $instance->classMethod()
would return some error. Does this also mean that instance method name shouldn't be shared by class method names? Or is 'static method' in php different from my understanding of a 'class method'?
<?php
class DemoClass{
static function classMethod(){
return "i'm a class method";
}
}
class ExampleTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$instance = new DemoClass;
$result1 = $instance->classMethod();
$result2 = DemoClass::classmethod();
$this->assertNotEquals($result1, $result2);
}
}
The result:
Failed asserting that 'i'm a class method' is not equal to <string:i'm a class method>.