Wednesday 25 September 2019

php - Can a class extend both a class and implement an Interface

Yes it can. You just need to retain the correct order.


class database extends mysqli implements databaseInterface { ... }

Moreover, a class can implement more than one interface. Just separate 'em with commas.


However, I feel obliged to warn you that extending mysqli class is incredibly bad idea. Inheritance per se is probably the most overrated and misused concept in object oriented programming.


Instead I'd advise doing db-related stuff the mysqli way (or PDO way).


Plus, a minor thing, but naming conventions do matter. Your class database seems more general then mysqli, therefore it suggests that the latter inherits from database and not the way around.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...