There is no apparent problem. That is to say, there is a problem which is not apparent in any way. There is surely a way to make this problem become apparent but it is not worth anyone's time to do so.
An observer is created for the table passed to the constructor.
An observer is created for the table passed to the constructor.
Irrelevant
OK, so the actual problem is this. Here is the constructor:
public function __construct(JTableInterface $table)
{
$table->attachObserver($this);
$this->table = $table;
}
Did you see it? Look closely. The type hinting doesn't require a JTable
, it requires a JTableInterface
. Great! We should write our functions for the interface, not for the class. This is the correct approach. But what is JTableInterface
and how does it relate to JTableObserver
? It's an interface for all of the usual table operations (bind
, check
, delete
, and etc..) but this constructor doesn't care at all about those table operations. This constructor calls attachObserver
which is from JObservableInterface
. JTable
implements this interface (and also JTableInterface
) so there's never any issue here as long as you are passing in a JTable
but the type hinting is not for JTable
, it's for JTableInterface
.
Should we change the type hinting so that the function expects a JObservableInterface
? That seems correct since we are immediately calling a function from that interface but it's not really correct. We do actually want to ensure that the thing passed into this constructor implements JTableInterface
as well because it may be used later by one of the event handling functions and they will surely want a JTableInterface
. Fine, then we can change the type hinting to JTable
since it implements both interfaces. That will work but it's not so great because, in theory, you should be able to create a class which is JTable
and does not inherit from JTable
but which does implement both interfaces. Yeah, nobody would do that but it's possible, in theory. Then, if you did that, even though it should be OK to pass an object of that class to this constructor, it would not be legal. There's not really a great solution to this issue and it's probably not a big deal in practice but still... it's wrong.
The interface was basically created for FOFTable and JTable to both work with Tags. Initially the interface contained the bind methods etc. But Don decided that he wanted the table class to be more generic so these methods were removed.
Category | ⇒ | Libraries |
Labels |
Added:
?
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-12-12 11:34:29 |
Closed_By | ⇒ | roland-d |
There's not really a great solution to this issue and it's probably not a big deal in practice but still... it's wrong.
Seems to be a catch-22, without a major rewrite I don't see this changed.
As such I am closing this issue, if someone wants to rewrite the code they can propose it in a new issue.
In practice:
https://github.com/joomla/joomla-cms/blob/staging/libraries/fof/table/table.php#L34