Skip to content

Commit

Permalink
Merge pull request #423 from dreamsxin/issues_404
Browse files Browse the repository at this point in the history
Fix #404 Updated IdenticalOperator.php and operators.h
  • Loading branch information
Phalcon committed Jun 18, 2014
2 parents e670854 + 3f79dd6 commit d1f35e1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Library/Operators/Comparison/IdenticalOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class IdenticalOperator extends ComparisonBaseOperator

protected $_zvalOperator = 'ZEPHIR_IS_IDENTICAL';

protected $_zvalLongOperator = 'ZEPHIR_IS_LONG';
protected $_zvalLongOperator = 'ZEPHIR_IS_LONG_IDENTICAL';

protected $_zvalLongNegOperator = 'ZEPHIR_IS_LONG';
protected $_zvalLongNegOperator = 'ZEPHIR_IS_LONG_IDENTICAL';

protected $_zvalStringOperator = 'ZEPHIR_IS_STRING';
protected $_zvalStringOperator = 'ZEPHIR_IS_STRING_IDENTICAL';

protected $_zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE';
protected $_zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE_IDENTICAL';

protected $_zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE';
protected $_zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE_IDENTICAL';
}
13 changes: 10 additions & 3 deletions ext/kernel/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@
#define ZEPHIR_IS_DOUBLE(op1, op2) ((Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) == op2) || zephir_compare_strict_double(op1, op2 TSRMLS_CC))
#define ZEPHIR_IS_STRING(op1, op2) zephir_compare_strict_string(op1, op2, strlen(op2))

#define ZEPHIR_IS_LONG_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) == op2)
#define ZEPHIR_IS_DOUBLE_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) == op2)
#define ZEPHIR_IS_STRING_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_STRING && zephir_compare_strict_string(op1, op2, strlen(op2)))

/** strict boolean comparison */
#define ZEPHIR_IS_FALSE(var) (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var))
#define ZEPHIR_IS_TRUE(var) (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var))
#define ZEPHIR_IS_FALSE(var) ((Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var)) || zephir_compare_strict_bool(var, 0 TSRMLS_CC))
#define ZEPHIR_IS_TRUE(var) ((Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var)) || zephir_compare_strict_bool(var, 1 TSRMLS_CC))

#define ZEPHIR_IS_FALSE_IDENTICAL(var) (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var))
#define ZEPHIR_IS_TRUE_IDENTICAL(var) (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var))

#define ZEPHIR_IS_NOT_FALSE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var)))
#define ZEPHIR_IS_NOT_TRUE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var)))
#define ZEPHIR_IS_BOOL(op1, op2) ((Z_TYPE_P(op1) == IS_BOOL && Z_BVAL_P(op1) == op2) || zephir_compare_strict_bool(op1, op2 TSRMLS_CC))

/** SQL null empty **/
#define ZEPHIR_IS_EMPTY(var) (Z_TYPE_P(var) == IS_NULL || (Z_TYPE_P(var) == IS_STRING && !Z_STRLEN_P(var)) || (Z_TYPE_P(var) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(var)) == 0))
#define ZEPHIR_IS_EMPTY(var) (Z_TYPE_P(var) == IS_NULL || ZEPHIR_IS_FALSE(var) || (Z_TYPE_P(var) == IS_STRING && !Z_STRLEN_P(var)) || (Z_TYPE_P(var) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(var)) == 0))
#define ZEPHIR_IS_NOT_EMPTY(var) (!ZEPHIR_IS_EMPTY(var))

/** Is scalar */
Expand Down
9 changes: 9 additions & 0 deletions test/operator.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Test;

class Operator
{
public function testIdentical(param1, param2)
{
return param1 === param2;
}
}
36 changes: 36 additions & 0 deletions unit-tests/Extension/OperatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013-2014 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

namespace Extension;

class OperatorTest extends \PHPUnit_Framework_TestCase
{
public function test404Issue()
{
$t = new \Test\Operator();

$this->assertFalse($t->testIdentical(true, 1));
$this->assertFalse($t->testIdentical(true, 'phalcon'));
$this->assertFalse($t->testIdentical(false, 0));
$this->assertFalse($t->testIdentical(1, '1'));
$this->assertTrue($t->testIdentical(1, 1));
$this->assertTrue($t->testIdentical(true, true));
$this->assertTrue($t->testIdentical('phalcon', 'phalcon'));
}
}

0 comments on commit d1f35e1

Please sign in to comment.