Giter VIP home page Giter VIP logo

pecl-php-operator's Introduction

Operator overloading extension for PHP7

Usage

Implement magic methods in a class to provide operator overloading automatically, for example:

class C {
  private $value = 0;
  public function __add($delta) {
    $this->value += $delta;
    return $this;
  }

  public function __toString() {
    return strval($this->value);
  }
}

$c = new C;
var_dump($c + 5); // object(C)#1 { ["C:value:private"]=>5 }

The following overload methods are supported:

Operator Method
$o + $arg __add($arg)
$o - $arg __sub($arg)
$o * $arg __mul($arg)
$o / $arg __div($arg)
$o % $arg __mod($arg)
$o ** $arg __pow($arg)
$o << $arg __sl($arg)
$o >> $arg __sr($arg)
$o . $arg __concat($arg)
$o | $arg __bw_or($arg)
$o & $arg __bw_and($arg)
$o ^ $arg __bw_xor($arg)
~$o __bw_not()
$o === $arg __is_identical($arg)
$o !== $arg __is_not_identical($arg)
$o == $arg __is_equal($arg)
$o != $arg __is_not_equal($arg)
$o < $arg __is_smaller($arg)
$o <= $arg __is_smaller_or_equal($arg)
$o > $arg __is_greater($arg) *
$o >= $arg __is_greater_or_equal($arg) *
$o <=> $arg __cmp($arg)
++$o __pre_inc()
$o++ __post_inc()
--$o __pre_dec()
$o-- __post_dec()
$o = $arg __assign($arg)
$o += $arg __assign_add($arg)
$o -= $arg __assign_sub($arg)
$o *= $arg __assign_mul($arg)
$o /= $arg __assign_div($arg)
$o %= $arg __assign_mod($arg)
$o **= $arg __assign_pow($arg)
$o <<= $arg __assign_sl($arg)
$o >>= $arg __assign_sr($arg)
$o .= $arg __assign_concat($arg)
$o |= $arg __assign_bw_or($arg)
$o &= $arg __assign_bw_and($arg)
$o ^= $arg __assign_bw_xor($arg)

* - __is_greater() and __is_greater_or_equal() require a rebuild of the main PHP runtime using the included patch. Withtout this patch, $a > $b is automatically remapped to $b < $a by the engine.

pecl-php-operator's People

Contributors

m6w6 avatar petk avatar pierrejoye avatar ryall avatar sebastianbergmann avatar sgolemon avatar svenrtbg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.