PHP Interface - What is PHP Interface and How to Use It
Vložit
- čas přidán 4. 08. 2024
- In this video I explain what PHP interface is and how to use it.
Upgrade your Clever Techie learning experience:
/ clevertechie
Download this video's files here:
/ php-interface-is-37524626
``````````````````````````````````````````````````````````````````````````````````````````````
( Website ) clevertechie.com - PHP, JavaScript, Wordpress, CSS, and HTML tutorials in video and text format with cool looking graphics and diagrams.
( CZcams Channel ) / clevertechietube
( Facebook ) / clevertechie
( Twitter ) / theclevertechie - Jak na to + styl
Very straightforward. Simple to understand
Thank you for good explanation!
thanks! finally i got it 👍
nice, thanks!
Perfect.
I guess I don't understand. Why write the interface if to still need to call the class/functions of the other class? Even the last part, you still copied and pasted the MySQL class to the new Oracle one.
Because the code of the function's implementation in the MySQL and Oracle classes can be different, this is the key thing to understand.
@@clevertechie why code cant be different with same names of functions without that additional interface part?
Answer : you can pass to function as a parametr class object and define in parameter, type of interface that object implements. Then, this function knows that this object has all necessary functions, so no error will occur. Example:
myFunc(InterfaceName $object).
2:41 aren't those supposed to called as "function declarations!?
Wow. Been a while???
What is your vscode theme setting including font?
Material Theme Ocean, Font: Consolas, 18
I don't seem to grasp the concept of, why would you use Interface if we are using the same name methods inside every classes anyway.
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
still don't get it ,
because thats just adding more size to your code while you can define the function + it functionality directly without the interface,
i thought its like in C# where you can update something live in the UI using interface , or at least sharing the same triggered information across the app as in C++ and UE blueprint
but in php it turn to be a joke , it just define a function name for you thats it . 0 real benefits
its like Filling a circle with the same color twice, while the first " Fill " was enough
Exactly that is what I am thinking. What is the point tho?
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
For example, say you have 10 classes implementing the same interface, and the interface has one method called echo_text(). You could loop over the 10 instances of those classes and call the echo_text() method on each of the 10 objects and be sure that method exists, without even knowing the implementation of the method.
weird, i've never seen anyone use spaces in their class filenames
When you are creating an object to the actual classes, then why you need an Interface? I mean the interface looks useless here.
You mean Abstraction and Interfaces are same thing
Polymorphism. Abstraction has to do with abstract classes
I don't understand. Why u are using interfaces.. Thoes work done by change class if your other class has same method you can change it your implementation class
I think Interfaces are used to make sure that all function that are needed are present in the class . what he missed was that if you forget to implement those function you get an error. An interface is a sort of contract and it's more about organizing code that provide a funtionality
@@thedude9014 your comment should be pinned
@@thedude9014 You nailed it. That's more precise