水曜日, 2月 15, 2012

PHP's overload: __call()

In my last blog, I wrote about PHP's get/set "overload", or hooking those methods for private members. There are more overloading method in PHP. The __call() method overload methods. This method "overloads" hidden member functions; including those methods that are non-existent. That is, you can create on the spot a brand new method just by calling __call().
class Test
{
  function __call($name,$parameter)
  {
    $value=$parameter[0];
    switch($name)
      {
      case "round":
        $value=round($value);
        break;
      case "floor":
        $value=floor($value);
        break;
      case "ceil":
        $value=ceil($value);
        break;
      }
    return $value;
  }
}

$test=new Test;
echo "Rounding: round(16.4) = ".$test->round(16.4);
echo "<br />";
echo "Floor: floor(16.4) = ".$test->floor(16.4);
echo "<br />";
echo "Ceiling: ceil(16.4) = ".$test->ceil(16.4);
echo "<br />";
This actually is a potential technological breakthrough -- in that the methods bears arbitrary names that are pseudo-defined and typed not dynamically then at programming time. This is a conceptual revolution in the programming. Remember, OOP is just a different form of C's structure.
Rounding: round(16.4) = 16
Floor: floor(16.4) = 16
Ceiling: ceil(16.4) = 17

Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...