update
This commit is contained in:
parent
76740aea81
commit
9e926d1bfb
|
@ -299,7 +299,31 @@ namespace php_arma
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void complex<T>::write_property(zval *obj, zval *member, zval *value, void **unused)
|
||||
zval *complex<T>::read_dimension(zval *obj, zval *offset, int type, zval*)
|
||||
{
|
||||
if (UNEXPECTED(Z_TYPE_P(offset) != IS_LONG)) {
|
||||
ex_bad_type("int", zval_get_type_name(offset));
|
||||
return nullptr;
|
||||
}
|
||||
if (UNEXPECTED(type != BP_VAR_R)) {
|
||||
zend_throw_exception_ex(zend_ce_exception, -2,
|
||||
"Numeric offset of class %s is read-only", Z_OBJNAME_P(obj));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto zobj = Z_OBJ_P(obj);
|
||||
auto idx = Z_LVAL_P(offset);
|
||||
if (EXPECTED(idx == 0 || idx == 1)) {
|
||||
return OBJ_PROP_NUM(zobj, idx);
|
||||
}
|
||||
|
||||
zend_throw_exception_ex(zend_ce_exception, -2,
|
||||
"Bad offset for %s, expected 0 or 1, %ld given.", Z_OBJNAME_P(obj), idx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void complex<T>::write_property(zval *obj, zval *member, zval *value, void**)
|
||||
{
|
||||
// Theoretically we won't get non-string values here, add type check just in case.
|
||||
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
|
||||
|
@ -382,6 +406,7 @@ namespace php_arma
|
|||
property_declare<T>(ce, "real");
|
||||
property_declare<T>(ce, "imag");
|
||||
object_handlers_init(&handlers);
|
||||
handlers.read_dimension = read_dimension;
|
||||
handlers.write_property = write_property;
|
||||
handlers.compare_objects = compare_objects;
|
||||
}
|
||||
|
|
|
@ -103,6 +103,7 @@ namespace php_arma
|
|||
static PHP_FUNCTION(acosh);
|
||||
static PHP_FUNCTION(atanh);
|
||||
|
||||
static zval *read_dimension(zval*, zval*, int, zval*);
|
||||
static void write_property(zval*, zval*, zval*, void**);
|
||||
static int compare_objects(zval*, zval*);
|
||||
|
||||
|
|
|
@ -11,10 +11,13 @@ is_php_arma_loaded();
|
|||
require_once 'includes/assert.php';
|
||||
|
||||
$cx_double = new Arma\CxDouble(1.2, 2.4);
|
||||
[$real, $imag] = $cx_double;
|
||||
|
||||
batch_assert('Arma\\Complex',
|
||||
[1.2, $cx_double->real],
|
||||
[2.4, $cx_double->imag]
|
||||
[2.4, $cx_double->imag],
|
||||
[$cx_double->real, $real],
|
||||
[$cx_double->imag, $imag]
|
||||
);
|
||||
|
||||
$cx_double->real *= 1.1;
|
||||
|
|
Reference in New Issue