?
avatar okonomiyaki3000
okonomiyaki3000
15 Dec 2014

Steps to reproduce the issue

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.

Expected result

An observer is created for the table passed to the constructor.

Actual result

An observer is created for the table passed to the constructor.

System information (as much as possible)

Irrelevant

Additional comments

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.

avatar okonomiyaki3000 okonomiyaki3000 - open - 15 Dec 2014
avatar Bakual
Bakual - comment - 15 Dec 2014

Yeah, nobody would do that but it's possible, in theory.

In practice:
https://github.com/joomla/joomla-cms/blob/staging/libraries/fof/table/table.php#L34

avatar wilsonge
wilsonge - comment - 15 Dec 2014

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.

avatar brianteeman brianteeman - change - 15 Dec 2014
Category Libraries
avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar roland-d roland-d - change - 12 Dec 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-12-12 11:34:29
Closed_By roland-d
avatar roland-d
roland-d - comment - 12 Dec 2015

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.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5430.

avatar roland-d roland-d - close - 12 Dec 2015

Add a Comment

Login with GitHub to post a comment