30
30
#include "phongo_compat.h"
31
31
#include "php_phongo.h"
32
32
33
+ #define PHONGO_OID_SIZE sizeof(((php_phongo_objectid_t *)0)->oid)
34
+ #define PHONGO_OID_LEN (PHONGO_OID_SIZE - 1)
35
+
33
36
zend_class_entry * php_phongo_objectid_ce ;
34
37
35
38
/* Initialize the object with a generated value and return whether it was
@@ -163,7 +166,7 @@ static PHP_METHOD(ObjectId, __toString)
163
166
return ;
164
167
}
165
168
166
- PHONGO_RETURN_STRINGL (intern -> oid , 24 );
169
+ PHONGO_RETURN_STRINGL (intern -> oid , PHONGO_OID_LEN );
167
170
} /* }}} */
168
171
169
172
/* {{{ proto array MongoDB\BSON\ObjectId::jsonSerialize()
@@ -179,7 +182,7 @@ static PHP_METHOD(ObjectId, jsonSerialize)
179
182
intern = Z_OBJECTID_OBJ_P (getThis ());
180
183
181
184
array_init_size (return_value , 1 );
182
- ADD_ASSOC_STRINGL (return_value , "$oid" , intern -> oid , 24 );
185
+ ADD_ASSOC_STRINGL (return_value , "$oid" , intern -> oid , PHONGO_OID_LEN );
183
186
} /* }}} */
184
187
185
188
/* {{{ proto string MongoDB\BSON\ObjectId::serialize()
@@ -199,11 +202,11 @@ static PHP_METHOD(ObjectId, serialize)
199
202
200
203
#if PHP_VERSION_ID >= 70000
201
204
array_init_size (& retval , 1 );
202
- ADD_ASSOC_STRINGL (& retval , "oid" , intern -> oid , 24 );
205
+ ADD_ASSOC_STRINGL (& retval , "oid" , intern -> oid , PHONGO_OID_LEN );
203
206
#else
204
207
ALLOC_INIT_ZVAL (retval );
205
208
array_init_size (retval , 1 );
206
- ADD_ASSOC_STRINGL (retval , "oid" , intern -> oid , 24 );
209
+ ADD_ASSOC_STRINGL (retval , "oid" , intern -> oid , PHONGO_OID_LEN );
207
210
#endif
208
211
209
212
PHP_VAR_SERIALIZE_INIT (var_hash );
@@ -358,7 +361,7 @@ static phongo_create_object_retval php_phongo_objectid_clone_object(zval* object
358
361
#endif
359
362
360
363
// Use memcpy to copy bson value to avoid converting to string and back
361
- memcpy (& new_intern -> oid , & intern -> oid , 25 );
364
+ memcpy (& new_intern -> oid , & intern -> oid , PHONGO_OID_SIZE );
362
365
new_intern -> initialized = true;
363
366
364
367
return new_object ;
0 commit comments