anybody explain overloading and overriding in php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

anybody explain overloading and overriding in php

give a example of overloading .overloading explain in details

10th Jul 2017, 5:01 PM
Gaurav - avatar
2 Answers
+ 2
here is an example in java but you may want to check to see difference or understand the meanings of overriding and overloading
11th Sep 2017, 3:01 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
overloading is when you take a function name or operator, and apply multiple definitions for different scenarios. it's handy when you have an object and want one function to handle different types of information. for example, I can create a function called "set" which will take an argument and store that information into different class variables. normally: setID (int id){...} setName (string name){....} OR set (int id){...} set (string name){...} in the overloaded function, all I need to do is use set, provide it with an integer or string, and it will handle the data appropriately. versus having to call setID or setName for each case in specific overriding is when you already have a name defined with a set of inputs, and force the code to use a different function instead. for example, if setName (string name){ do A } is defined in a parent, overriding it in the child would be writing a function like setName (string name){ do B } A good scenario would be if you were writing a program to draw shapes. the parent class would be called Shape and it could have a few methods like Shape.draw and Shape.originCoordinates in a child class, you would override the draw function so rectangle wouldn't draw the same thing as a circle.
13th Jul 2017, 6:15 AM
Andrew Lampert
Andrew Lampert - avatar