{"id":450,"date":"2014-09-28T13:21:05","date_gmt":"2014-09-28T21:21:05","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=450"},"modified":"2014-09-28T13:21:24","modified_gmt":"2014-09-28T21:21:24","slug":"overloading-in-php","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=450","title":{"rendered":"Overloading in PHP"},"content":{"rendered":"<p>Overloading has a different meaning in PHP. PHP does not support function overloading in the same manner as C++. However it possible to pass different number of arguments to a function using func_get_args.  <\/p>\n<p><code>function findSum() {<br \/>\n    $sum = 0;<br \/>\n    foreach (func_get_args() as $arg) {<br \/>\n        $sum += $arg;<br \/>\n    }<br \/>\n    return $sum;<br \/>\n}<\/p>\n<p>echo findSum(1, 2), '<br \/>'; \/\/outputs 3<br \/>\necho findSum(10, 2, 100), '<br \/>'; \/\/outputs 112<br \/>\necho findSum(10, 22, 0.5, 0.75, 12.50), '<br \/>'; \/\/outputs 45.75<\/code><\/p>\n<p>Overloading in PHP provides means to dynamically &#8220;create&#8221; properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.<br \/>\nThe overloading methods are invoked when interacting with properties or methods that have not been declared or are not visible in the current scope.<br \/>\nExample for property overloading: __set() and __get()<br \/>\nExample for method overloading: __call()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overloading has a different meaning in PHP. PHP does not support function overloading in the same manner as C++. However it possible to pass different number of arguments to a function using func_get_args. function findSum() { $sum = 0; foreach (func_get_args() as $arg) { $sum += $arg; } return $sum; } echo findSum(1, 2), &#8221;; &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=450\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Overloading in PHP<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-450","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=450"}],"version-history":[{"count":2,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions"}],"predecessor-version":[{"id":452,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/450\/revisions\/452"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}