samedi 28 mars 2015

Casting object to its interface from a point of view of PHP



I am trying to rewrite Java code to PHP (for a educational reasons) and I hava a problem with understanding the casting thing. The problematic code is located (for example) here (line 46). As we can see the object returned by this.getBoard().getTile(boxActualPlace) is casted to interface ContentOperations (link) and then the inteface method getContent is invoked. From what I understand from the code, getTile method not always returns an object that implements that interface, so this casting thing maybe some kind of protection from invoking non-existent method, but since I know nothing about Java I would like to ask for confirmation of my theory and for tips on how to implement this in PHP. I will be grateful for any help!




Aucun commentaire:

Enregistrer un commentaire