I have this base class:
<?php
use Parse\ParseObject;
use Parse\ParseQuery;
class BaseModel extends ParseObject
{
public static $className = 'PlaceHolder';
public static function query() {
return new ParseQuery(self::$className);
}
}
And this child class
<?php
class Post extends BaseModel
{
public static $className = 'Post';
}
When I call Post::$className I get 'Post' but when I use Post::query() it uses the parent classes value 'PlaceHolder'.
Why does the inherited static function use the value from the parent class?
The query
function is defined in the parent class and will thus use the value of that class. This is a limitation of the self
keyword. You will want to look into Late Static Binding to get around this.
public static function query() {
return new ParseQuery(static::$className);
}