1
0
Fork 0
mirror of https://github.com/laravel-ls/go-php synced 2026-06-16 03:54:55 +02:00
go-php/zval.c
2025-11-02 10:47:20 +01:00

54 lines
1.2 KiB
C

#include <Zend/zend_types.h>
#include <Zend/zend_operators.h>
#include "zval.h"
zval new_zval() {
zval val;
ZVAL_NULL(&val);
return val;
}
void zval_destroy(zval *val) {
zval_dtor(val);
ZVAL_NULL(val);
}
zend_array* zval_get_array(zval *zv) {
return Z_ARRVAL_P(zv);
}
// Initialize a hash table traversal
void zend_array_init_traverse(zend_array *arr, HashPosition *pos) {
zend_hash_internal_pointer_reset_ex(arr, pos);
}
void zval_set_long(zval *val, long int num) {
ZVAL_LONG(val, num);
}
// Get the next entry in the hash table
int zend_array_get_next(zend_array *arr, HashPosition *pos, hash_table_entry *entry) {
zend_string *key_str = NULL;
zend_ulong key_long = 0;
zval *value = zend_hash_get_current_data_ex(arr, pos);
if (!value) {
return 0; // End of the array
}
if (zend_hash_get_current_key_ex(arr, &key_str, &key_long, pos) == HASH_KEY_IS_STRING) {
entry->key_type = HASH_KEY_IS_STRING;
entry->key_str = key_str;
} else {
entry->key_type = HASH_KEY_IS_LONG;
entry->key_long = key_long;
}
entry->value = *value;
zend_hash_move_forward_ex(arr, pos);
return 1; // Entry found
}
char* zend_string_cstr(zend_string *zstr) {
return zstr ? ZSTR_VAL(zstr) : NULL;
}