summaryrefslogtreecommitdiff
path: root/zend/value.cpp
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-06-11 16:36:01 +0600
committervalmat <ufabiz@gmail.com>2014-06-11 16:36:01 +0600
commita3aea78834102b7d0f206c73463de69050f15076 (patch)
treebbfb1878b104b7dbd2ada2a694236fa09351b97f /zend/value.cpp
parent5ba897e11fc7a4648a9323ed2bb74c1ac6aa57d8 (diff)
Corrected in accordance with Proposition https://github.com/CopernicaMarketingSoftware/PHP-CPP/pull/95#issuecomment-45716890
Diffstat (limited to 'zend/value.cpp')
-rw-r--r--zend/value.cpp49
1 files changed, 21 insertions, 28 deletions
diff --git a/zend/value.cpp b/zend/value.cpp
index 477017a..74c84e5 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -1318,21 +1318,20 @@ Value Value::exec(const char *name, int argc, struct _zval_struct ***params)
*/
bool Value::operator==(const Value &value) const
{
- auto tp = type();
- if(tp != value.type())
- return false;
+ Type tp = type();
+ const _zval_struct *thatval = (tp == value.type()) ? value._val : value.clone(tp)._val;
switch (tp) {
case Type::Null: return true;
- case Type::Numeric: return (_val->value.lval == value._val->value.lval);
- case Type::Float: return (_val->value.dval == value._val->value.dval);
- case Type::Bool: return (_val->value.lval == value._val->value.lval);
- case Type::String: return (_val->value.str.len && value._val->value.str.len) && (::strcmp(_val->value.str.val, value._val->value.str.val) == 0);
+ case Type::Numeric: return (_val->value.lval == thatval->value.lval);
+ case Type::Float: return (_val->value.dval == thatval->value.dval);
+ case Type::Bool: return (_val->value.lval == thatval->value.lval);
+ case Type::String: return (_val->value.str.len && thatval->value.str.len) && (::strcmp(_val->value.str.val, thatval->value.str.val) == 0);
// @todo
case Type::Array: throw Php::Exception("TODO implement comparison arrays"); break;
// @todo
case Type::Object: throw Php::Exception("TODO implement comparison arrays"); break;
- case Type::Resource: return (_val->value.lval == value._val->value.lval);
+ case Type::Resource: return (_val->value.lval == thatval->value.lval);
case Type::Constant: throw Php::Exception("Constant types can not be assigned to a PHP-CPP library variable"); break;
case Type::ConstantArray: throw Php::Exception("Constant types can not be assigned to a PHP-CPP library variable"); break;
case Type::Callable: throw Php::Exception("Callable types can not be assigned to a PHP-CPP library variable"); break;
@@ -1342,18 +1341,15 @@ bool Value::operator==(const Value &value) const
}
bool Value::operator< (const Value &value) const
{
- auto tp = type();
- if(tp != value.type()){
- // @todo maybe this can be improved
- throw Php::Exception("It is not possible to compare different types");
- return false;
- }
+ Type tp = type();
+ const _zval_struct *thatval = (tp == value.type()) ? value._val : value.clone(tp)._val;
+
switch (tp) {
case Type::Null: return false;
- case Type::Numeric: return (_val->value.lval < value._val->value.lval);
- case Type::Float: return (_val->value.dval < value._val->value.dval);
- case Type::Bool: return (_val->value.lval < value._val->value.lval);
- case Type::String: return (::strcmp(_val->value.str.val, value._val->value.str.val) < 0);
+ case Type::Numeric: return (_val->value.lval < thatval->value.lval);
+ case Type::Float: return (_val->value.dval < thatval->value.dval);
+ case Type::Bool: return (_val->value.lval < thatval->value.lval);
+ case Type::String: return (::strcmp(_val->value.str.val, thatval->value.str.val) < 0);
// @todo
case Type::Array: throw Php::Exception("TODO implement comparison arrays"); break;
// @todo
@@ -1367,18 +1363,15 @@ bool Value::operator< (const Value &value) const
}
bool Value::operator> (const Value &value) const
{
- auto tp = type();
- if(tp != value.type()){
- // @todo maybe this can be improved
- throw Php::Exception("It is not possible to compare different types");
- return false;
- }
+ Type tp = type();
+ const _zval_struct *thatval = (tp == value.type()) ? value._val : value.clone(tp)._val;
+
switch (tp) {
case Type::Null: return false;
- case Type::Numeric: return (_val->value.lval > value._val->value.lval);
- case Type::Float: return (_val->value.dval > value._val->value.dval);
- case Type::Bool: return (_val->value.lval > value._val->value.lval);
- case Type::String: return (::strcmp(_val->value.str.val, value._val->value.str.val) > 0);
+ case Type::Numeric: return (_val->value.lval > thatval->value.lval);
+ case Type::Float: return (_val->value.dval > thatval->value.dval);
+ case Type::Bool: return (_val->value.lval > thatval->value.lval);
+ case Type::String: return (::strcmp(_val->value.str.val, thatval->value.str.val) > 0);
// @todo
case Type::Array: throw Php::Exception("TODO implement comparison arrays"); break;
// @todo