I am using PHP Version 5.2.5.
I want to be able to compare my own class with int.
abstract class A {
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function __toString()
{
return $this->value;
}
}
class B extends A { }
but I want to be able to use my class like this:
$inst = new B(20);
if($inst==20) {
//...
}
how I can do it?
You could use a magic __toString() method in your class.
Technically, __toString() must return a string rather than an integer, but PHP’s loose typing will make the comparison using standard loose typing comparison rules