PHP 8.4.24 Released!

Voting

: min(five, eight)?
(Example: nine)

The Note You're Voting On

turabgarip at gmail dot com
5 years ago
I concur that "overloading" is a wrong term for this functionality. But I disagree that this functionality is completely wrong. You can do "bad practice" with right code too.

For example __call() is very well applicable to external integration implementations which I am using to relay calls to SOAP methods which doesn't need local implementation. So you don't have to write "empty body" functions. Consider the SOAP service you connect has a "stock update" method. All you have to do is passing product code and stock count to SOAP.

<?php

class Inventory {

  public __construct() {
    // configure and connect to SOAP service
    $this->soap = new SoapClient();
  }

  public __call($soapMethod, $params) {
    $this->soap->{$soapMethod}(params);
  }
}

 // Now you can use any SOAP method without needing a wrapper
 $stock = new Inventory();
 $stock->updatePrice($product_id, 20);
 $stock->saveProduct($product_info);
 
?>

Of course you'd need a parameter mapping but it's in my honest opinion a lot better then having a plenty of mirror methods like:

<?php

class Inventory {

  public function updateStock($product_id, $stock) {
    $soapClient->updateStock($product_id, $stock;
  }
  public function updatePrice($product_id, $price) {
    $soapClient->updateStock($product_id, $price;
  }
  // ...
}

?>

<< Back to user notes page

To Top