php_vm 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/ext/php_vm/php_vm.c CHANGED
@@ -17,6 +17,7 @@ VALUE rb_ePHPErrorReporting;
17
17
 
18
18
 
19
19
  // PHP Embed
20
+
20
21
  static int php_embed_output_handler(const char *str, unsigned int str_length TSRMLS_DC)
21
22
  {
22
23
  VALUE proc = rb_cv_get(rb_mPHPVM, "@@output_handler");
@@ -48,10 +49,14 @@ static void php_embed_error_handler(char *message)
48
49
  }
49
50
  }
50
51
 
52
+ static zval *global_exception = NULL;
51
53
  static void php_vm_exception_hook(zval *ex TSRMLS_DC)
52
54
  {
53
- VALUE exception = zval_to_value(ex);
54
- rb_exc_raise(exception);
55
+ // TODO: no use global variable
56
+ //VALUE exception = zval_to_value(ex);
57
+ //rb_exc_raise(exception);
58
+ global_exception = ex;
59
+ EG(exception) = NULL;
55
60
  }
56
61
 
57
62
 
@@ -70,8 +75,7 @@ void php_eval_string(char *code, int code_len TSRMLS_DC)
70
75
 
71
76
  // syntax error
72
77
  if (syntax_error) {
73
- VALUE exception = rb_exc_new2(rb_ePHPSyntaxError, "Syntax error");
74
- rb_exc_raise(exception);
78
+ rb_raise(rb_ePHPSyntaxError, "Syntax error");
75
79
  }
76
80
 
77
81
  // exception
@@ -86,11 +90,7 @@ void php_eval_string(char *code, int code_len TSRMLS_DC)
86
90
  int exit_status = EG(exit_status);
87
91
  EG(exit_status) = 0;
88
92
 
89
- char message[32];
90
- sprintf(message, "exit status error: %d", exit_status);
91
-
92
- VALUE exception = rb_exc_new2(rb_ePHPError, message);
93
- rb_exc_raise(exception);
93
+ rb_raise(rb_ePHPError, "exit status error: %d", exit_status);
94
94
  }
95
95
  }
96
96
 
@@ -171,27 +171,19 @@ int new_php_object(zend_class_entry *ce, VALUE v_args, zval *retval)
171
171
  // defined constructor
172
172
  /*
173
173
  if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
174
- char *message = malloc(50+strlen(ce->name));
175
- sprintf(message, "Access to non-public constructor of class %s", ce->name);
176
- VALUE v_exception = rb_exc_new2(rb_ePHPError, message);
177
- free(message);
178
- rb_exc_raise(v_exception);
174
+ rb_raise(rb_ePHPError, "Access to non-public constructor of class %s", ce->name);
179
175
  }
180
176
  */
181
177
 
182
178
  // alloc
183
179
  object_init_ex(retval, ce);
184
180
 
185
- // call
181
+ // call constructor
186
182
  int result = call_php_method(ce, retval, ce->constructor, RARRAY_LEN(v_args), RARRAY_PTR(v_args), &retval TSRMLS_CC);
187
183
 
188
184
  // error
189
185
  if (result==FAILURE) {
190
- char *message = malloc(40+strlen(ce->name));
191
- sprintf(message, "Invocation of %s's constructor failed", ce->name);
192
- VALUE v_exception = rb_exc_new2(rb_ePHPError, message);
193
- free(message);
194
- rb_exc_raise(v_exception);
186
+ rb_raise(rb_ePHPError, "Invocation of %s's constructor failed", ce->name);
195
187
  }
196
188
 
197
189
  } else if (!RARRAY_LEN(v_args)) {
@@ -201,11 +193,7 @@ int new_php_object(zend_class_entry *ce, VALUE v_args, zval *retval)
201
193
 
202
194
  } else {
203
195
  // undefine constructor, has args
204
- char *message = malloc(90+strlen(ce->name));
205
- sprintf(message, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
206
- VALUE v_exception = rb_exc_new2(rb_ePHPError, message);
207
- free(message);
208
- rb_exc_raise(v_exception);
196
+ rb_raise(rb_ePHPError, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
209
197
  }
210
198
  return result;
211
199
  }
@@ -292,9 +280,9 @@ void define_php_methods(VALUE v_obj, zend_class_entry *ce, int is_static)
292
280
  }
293
281
  }
294
282
 
295
- void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, int is_static)
283
+ void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, zval *zobj)
296
284
  {
297
- if (is_static) {
285
+ if (!zobj) {
298
286
  // static method
299
287
  if (ce->__callstatic) {
300
288
  rb_define_singleton_method(v_obj, "__callStatic", rb_php_class_call_magic___callstatic, 2);
@@ -302,21 +290,27 @@ void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, int is_static)
302
290
  }
303
291
  } else {
304
292
  // instance method
293
+ const zend_object_handlers *h = Z_OBJ_HT_P(zobj);
294
+ int has_get = h->read_property!=std_object_handlers.read_property || (h->read_property && ce->__get);
295
+ int has_set = h->write_property!=std_object_handlers.write_property || (h->write_property &&ce->__set);
296
+ int has_unset = h->unset_property!=std_object_handlers.unset_property || (h->unset_property && ce->__unset);
297
+ int has_isset = h->has_property!=std_object_handlers.has_property || (h->has_property && ce->__isset);
298
+
305
299
  if (ce->clone) {
306
300
  rb_define_singleton_method(v_obj, "__clone", rb_php_object_call_magic_clone, 0);
307
301
  rb_define_singleton_method(v_obj, "dup", rb_php_object_call_magic_clone, 0);
308
302
  rb_define_singleton_method(v_obj, "clone", rb_php_object_call_magic_clone, 0);
309
303
  }
310
- if (ce->__get) {
304
+ if (has_get) {
311
305
  rb_define_singleton_method(v_obj, "__get", rb_php_object_call_magic___get, 1);
312
306
  }
313
- if (ce->__set) {
307
+ if (has_set) {
314
308
  rb_define_singleton_method(v_obj, "__set", rb_php_object_call_magic___set, 2);
315
309
  }
316
- if (ce->__unset) {
310
+ if (has_unset) {
317
311
  rb_define_singleton_method(v_obj, "__unset", rb_php_object_call_magic___unset, 1);
318
312
  }
319
- if (ce->__isset) {
313
+ if (has_isset) {
320
314
  rb_define_singleton_method(v_obj, "__isset", rb_php_object_call_magic___isset, 1);
321
315
  }
322
316
  if (ce->__call) {
@@ -324,8 +318,10 @@ void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, int is_static)
324
318
  }
325
319
  if (ce->__tostring) {
326
320
  rb_define_singleton_method(v_obj, "__toString", rb_php_object_call_magic___tostring, 0);
321
+ rb_define_singleton_method(v_obj, "to_s", rb_php_object_call_magic___tostring, 0);
327
322
  }
328
- if (ce->__call || ce->__get || ce->__set) {
323
+
324
+ if (has_get || has_set || ce->__call) {
329
325
  rb_define_singleton_method(v_obj, "method_missing", rb_php_object_call_method_missing, -1);
330
326
  }
331
327
  }
@@ -370,7 +366,7 @@ int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int ar
370
366
 
371
367
  zend_fcall_info_args(&fci, z_args);
372
368
 
373
- // call
369
+ // call method
374
370
  zend_try {
375
371
  result = zend_call_function(&fci, &fcc TSRMLS_CC);
376
372
  } zend_catch {
@@ -424,13 +420,12 @@ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, zend_function *mpt
424
420
  int result = call_php_method(ce, obj, mptr, argc, argv, &z_val TSRMLS_CC);
425
421
 
426
422
  // exception
427
- if (result==FAILURE) {
428
- const char *mname = mptr->common.function_name;
429
- char *message = malloc(32+strlen(mname));
430
- sprintf(message, "raise exception: %s", mname);
431
- VALUE exception = rb_exc_new2(rb_ePHPError, message);
432
- free(message);
423
+ if (global_exception) {
424
+ VALUE exception = zval_to_value(global_exception);
425
+ global_exception = NULL;
433
426
  rb_exc_raise(exception);
427
+ } else if (result==FAILURE) {
428
+ rb_raise(rb_ePHPError, "raise exception: %s", mptr->common.function_name);
434
429
  }
435
430
 
436
431
  return zval_to_value(z_val);
@@ -442,8 +437,7 @@ VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee,
442
437
 
443
438
  // callee
444
439
  if (callee==Qnil) {
445
- VALUE exception = rb_exc_new2(rb_ePHPError, "callee is nil");
446
- rb_exc_raise(exception);
440
+ rb_raise(rb_ePHPError, "callee is nil");
447
441
  }
448
442
 
449
443
  // method
@@ -457,12 +451,12 @@ VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee,
457
451
  int result = call_php_method(ce, obj, mptr, argc, argv, &z_val TSRMLS_CC);
458
452
 
459
453
  // exception
460
- if (result==FAILURE) {
461
- char *message = malloc(32+RSTRING_LEN(callee));
462
- sprintf(message, "raise exception: %s", RSTRING_PTR(callee));
463
- VALUE exception = rb_exc_new2(rb_ePHPError, message);
464
- free(message);
454
+ if (global_exception) {
455
+ VALUE exception = zval_to_value(global_exception);
456
+ global_exception = NULL;
465
457
  rb_exc_raise(exception);
458
+ } else if (result==FAILURE) {
459
+ rb_raise(rb_ePHPError, "raise exception: %s", RSTRING_PTR(callee));
466
460
  }
467
461
  } else {
468
462
  // accessor
@@ -849,8 +843,7 @@ VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE cls)
849
843
  int i;
850
844
 
851
845
  if (argc==0) {
852
- VALUE exception = rb_exc_new2(rb_eArgError, "Too few arguments");
853
- rb_exc_raise(exception);
846
+ rb_raise(rb_eArgError, "Too few arguments");
854
847
  }
855
848
 
856
849
  // format
@@ -924,11 +917,7 @@ VALUE rb_php_class_initialize(VALUE self, VALUE v_name)
924
917
 
925
918
  // class not found
926
919
  if (!ce) {
927
- char *message = malloc(32+RSTRING_LEN(v_name));
928
- sprintf(message, "Class is not found: %s", RSTRING_PTR(v_name));
929
- VALUE exception = rb_exc_new2(rb_ePHPError, message);
930
- free(message);
931
- rb_exc_raise(exception);
920
+ rb_raise(rb_ePHPError, "Class is not found: %s", RSTRING_PTR(v_name));
932
921
  }
933
922
 
934
923
  // set resource
@@ -941,7 +930,7 @@ VALUE rb_php_class_initialize(VALUE self, VALUE v_name)
941
930
  // define php static properties and methods
942
931
  define_php_properties(self, *ce, 1);
943
932
  define_php_methods(self, *ce, 1);
944
- define_php_magic_method(self, *ce, 1);
933
+ define_php_magic_method(self, *ce, NULL);
945
934
 
946
935
  return self;
947
936
  }
@@ -966,11 +955,6 @@ VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self)
966
955
  }
967
956
  rb_php_object_initialize(obj, self, args);
968
957
 
969
- // define php instance properties and methods
970
- define_php_properties(obj, ce, 0);
971
- define_php_methods(obj, ce, 0);
972
- define_php_magic_method(obj, ce, 0);
973
-
974
958
  return obj;
975
959
  }
976
960
 
@@ -1036,6 +1020,11 @@ VALUE rb_php_object_initialize(VALUE self, VALUE class, VALUE args)
1036
1020
  VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, php_native_resource_delete, p);
1037
1021
  rb_iv_set(self, "php_native_resource", resource);
1038
1022
 
1023
+ // define php instance properties and methods
1024
+ define_php_properties(self, ce, 0);
1025
+ define_php_methods(self, ce, 0);
1026
+ define_php_magic_method(self, ce, z_obj);
1027
+
1039
1028
  return self;
1040
1029
  }
1041
1030
 
@@ -1070,15 +1059,19 @@ VALUE rb_php_object_call(int argc, VALUE *argv, VALUE self)
1070
1059
 
1071
1060
  VALUE rb_php_object_call_magic_clone(VALUE self)
1072
1061
  {
1062
+ TSRMLS_FETCH();
1063
+
1073
1064
  zval *zobj = get_zval(self);
1065
+ zend_object_clone_obj_t handler = Z_OBJ_HT_P(zobj)->clone_obj;
1066
+ if (!handler) {
1067
+ rb_raise(rb_ePHPError, "clone_obj handler is not defined");
1068
+ }
1074
1069
 
1075
- zend_object_clone_obj_t clone_call = Z_OBJ_HT_P(zobj)->clone_obj;
1076
1070
  zval *retval;
1077
-
1078
1071
  ALLOC_ZVAL(retval);
1079
- Z_OBJVAL_P(retval) = clone_call(zobj TSRMLS_CC);
1072
+ Z_OBJVAL_P(retval) = handler(zobj TSRMLS_CC);
1080
1073
  Z_TYPE_P(retval) = IS_OBJECT;
1081
- Z_SET_REFCOUNT_P(retval, 1);
1074
+ Z_SET_REFCOUNT_P(retval, 0);
1082
1075
  Z_SET_ISREF_P(retval);
1083
1076
 
1084
1077
  return zval_to_value(retval);
@@ -1086,35 +1079,88 @@ VALUE rb_php_object_call_magic_clone(VALUE self)
1086
1079
 
1087
1080
  VALUE rb_php_object_call_magic___get(VALUE self, VALUE name)
1088
1081
  {
1089
- zend_class_entry *ce = get_zend_class_entry(self);
1082
+ TSRMLS_FETCH();
1083
+
1090
1084
  zval *zobj = get_zval(self);
1085
+ zend_object_read_property_t handler = Z_OBJ_HT_P(zobj)->read_property;
1086
+ if (!handler) {
1087
+ rb_raise(rb_ePHPError, "read_property handler is not defined");
1088
+ }
1089
+
1090
+ zval *member;
1091
+ MAKE_STD_ZVAL(member);
1092
+ ZVAL_STRING(member, RSTRING_PTR(name), 1);
1093
+
1094
+ zval *retval;
1095
+ retval = handler(zobj, member, BP_VAR_IS, NULL TSRMLS_CC);
1091
1096
 
1092
- return call_php_method_bridge(ce, zobj, ce->__get, 1, &name);
1097
+ zval_ptr_dtor(&member);
1098
+ return zval_to_value(retval);
1093
1099
  }
1094
1100
 
1095
1101
  VALUE rb_php_object_call_magic___set(VALUE self, VALUE name, VALUE arg)
1096
1102
  {
1097
- zend_class_entry *ce = get_zend_class_entry(self);
1103
+ TSRMLS_FETCH();
1104
+
1098
1105
  zval *zobj = get_zval(self);
1099
- VALUE args[2] = {name, arg};
1106
+ zend_object_write_property_t handler = Z_OBJ_HT_P(zobj)->write_property;
1107
+ if (!handler) {
1108
+ rb_raise(rb_ePHPError, "write_property handler is not defined");
1109
+ }
1110
+
1111
+ zval *member;
1112
+ MAKE_STD_ZVAL(member);
1113
+ ZVAL_STRING(member, RSTRING_PTR(name), 1);
1100
1114
 
1101
- return call_php_method_bridge(ce, zobj, ce->__set, 2, args);
1115
+ zval *z_arg;
1116
+ value_to_zval(arg, &z_arg);
1117
+
1118
+ handler(zobj, member, z_arg, NULL TSRMLS_CC);
1119
+
1120
+ zval_ptr_dtor(&member);
1121
+ zval_ptr_dtor(&z_arg);
1122
+ return Qnil;
1102
1123
  }
1103
1124
 
1104
1125
  VALUE rb_php_object_call_magic___unset(VALUE self, VALUE name)
1105
1126
  {
1106
- zend_class_entry *ce = get_zend_class_entry(self);
1127
+ TSRMLS_FETCH();
1128
+
1107
1129
  zval *zobj = get_zval(self);
1130
+ zend_object_unset_property_t handler = Z_OBJ_HT_P(zobj)->unset_property;
1131
+ if (!handler) {
1132
+ rb_raise(rb_ePHPError, "unset_property handler is not defined");
1133
+ }
1108
1134
 
1109
- return call_php_method_bridge(ce, zobj, ce->__unset, 1, &name);
1135
+ zval *member;
1136
+ MAKE_STD_ZVAL(member);
1137
+ ZVAL_STRING(member, RSTRING_PTR(name), 1);
1138
+
1139
+ handler(zobj, member, NULL TSRMLS_CC);
1140
+
1141
+ zval_ptr_dtor(&member);
1142
+ return Qnil;
1110
1143
  }
1111
1144
 
1112
1145
  VALUE rb_php_object_call_magic___isset(VALUE self, VALUE name)
1113
1146
  {
1114
- zend_class_entry *ce = get_zend_class_entry(self);
1147
+ TSRMLS_FETCH();
1148
+
1115
1149
  zval *zobj = get_zval(self);
1150
+ zend_object_has_property_t handler = Z_OBJ_HT_P(zobj)->has_property;
1151
+ if (!handler) {
1152
+ rb_raise(rb_ePHPError, "has_property handler is not defined");
1153
+ }
1116
1154
 
1117
- return call_php_method_bridge(ce, zobj, ce->__isset, 1, &name);
1155
+ zval *member;
1156
+ MAKE_STD_ZVAL(member);
1157
+ ZVAL_STRING(member, RSTRING_PTR(name), 1);
1158
+
1159
+ int has;
1160
+ has = handler(zobj, member, 0, NULL TSRMLS_CC);
1161
+
1162
+ zval_ptr_dtor(&member);
1163
+ return has ? Qtrue : Qfalse;
1118
1164
  }
1119
1165
 
1120
1166
  VALUE rb_php_object_call_magic___call(VALUE self, VALUE name, VALUE args)
@@ -1123,6 +1169,10 @@ VALUE rb_php_object_call_magic___call(VALUE self, VALUE name, VALUE args)
1123
1169
  zval *zobj = get_zval(self);
1124
1170
  VALUE argv[2] = {name, args};
1125
1171
 
1172
+ if (args==Qnil || TYPE(args)!=T_ARRAY) {
1173
+ rb_raise(rb_eArgError, "args is not array");
1174
+ }
1175
+
1126
1176
  return call_php_method_bridge(ce, zobj, ce->__call, 2, argv);
1127
1177
  }
1128
1178
 
@@ -1152,20 +1202,15 @@ VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self)
1152
1202
  VALUE name, val;
1153
1203
  rb_scan_args(argc, argv, "11", &name, &val);
1154
1204
  name = rb_str_new2(rb_id2name(SYM2ID(name)));
1155
- VALUE argv2[2] = {name, val};
1156
1205
 
1157
1206
  VALUE is_setter = rb_funcall(name, rb_intern("end_with?"), 1, rb_str_new2("="));
1158
1207
  if (is_setter) {
1159
1208
  // __set
1160
- if (ce->__set) {
1161
- rb_funcall(name, rb_intern("gsub!"), 2, rb_str_new2("="), rb_str_new2(""));
1162
- return call_php_method_bridge(ce, zobj, ce->__set, 2, argv2);
1163
- }
1209
+ rb_funcall(name, rb_intern("gsub!"), 2, rb_str_new2("="), rb_str_new2(""));
1210
+ return rb_php_object_call_magic___set(self, name, val);
1164
1211
  } else {
1165
1212
  // __get
1166
- if (ce->__get) {
1167
- return call_php_method_bridge(ce, zobj, ce->__get, 1, argv2);
1168
- }
1213
+ return rb_php_object_call_magic___get(self, name);
1169
1214
  }
1170
1215
  }
1171
1216
  return Qnil;
@@ -1290,7 +1335,7 @@ void Init_php_vm()
1290
1335
  rb_define_singleton_method(rb_mPHPVM, "get_class", rb_php_vm_get_class, 1);
1291
1336
  rb_define_singleton_method(rb_mPHPVM, "define_global", rb_php_vm_define_global, 0);
1292
1337
 
1293
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.6"));
1338
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.7"));
1294
1339
 
1295
1340
  rb_cv_set(rb_mPHPVM, "@@output_handler", Qnil);
1296
1341
  rb_cv_set(rb_mPHPVM, "@@error_handler", Qnil);
data/ext/php_vm/php_vm.h CHANGED
@@ -28,12 +28,14 @@ typedef struct {
28
28
  // PHP
29
29
  extern void php_eval_string(char *code, int code_len TSRMLS_DC);
30
30
  extern void find_zend_class_entry(char *name, int name_len, zend_class_entry ***ce);
31
- extern void find_zend_class_entry2(char *name, zend_class_entry ***ce);
32
31
  extern int is_exception_zend_class_entry(zend_class_entry *ce TSRMLS_DC);
33
32
  extern int is_exception_zval(zval *z TSRMLS_DC);
33
+ extern void find_zend_function(zend_class_entry *ce, char *name, int name_len, zend_function **mptr);
34
+ extern int has_zend_function(zend_class_entry *ce, VALUE method_name);
34
35
  extern int new_php_object(zend_class_entry *ce, VALUE v_args, zval *retval);
35
36
  extern void define_php_properties(VALUE v_obj, zend_class_entry *ce, int is_static);
36
37
  extern void define_php_methods(VALUE v_obj, zend_class_entry *ce, int is_static);
38
+ extern void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, zval *zobj);
37
39
  extern int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int argc, VALUE *v_argv, zval **retval_ptr TSRMLS_DC);
38
40
 
39
41
  // Ruby
@@ -48,13 +50,17 @@ extern zend_class_entry* get_zend_class_entry(VALUE self);
48
50
  extern zval* get_zval(VALUE self);
49
51
 
50
52
  // module PHPVM
51
- extern void php_vm_require(char *construct, VALUE filepath);
53
+ extern VALUE rb_php_vm_get_output_handler(VALUE cls);
54
+ extern VALUE rb_php_vm_set_output_handler(VALUE cls, VALUE proc);
55
+ extern VALUE rb_php_vm_get_error_handler(VALUE cls);
56
+ extern VALUE rb_php_vm_set_error_handler(VALUE cls, VALUE proc);
57
+ extern void php_vm_require(char *token, VALUE filepath);
52
58
  extern VALUE rb_php_vm_require(VALUE cls, VALUE filepath);
53
59
  extern VALUE rb_php_vm_require_once(VALUE cls, VALUE filepath);
54
60
  extern VALUE rb_php_vm_include(VALUE cls, VALUE filepath);
55
61
  extern VALUE rb_php_vm_include_once(VALUE cls, VALUE filepath);
56
- extern VALUE rb_php_vm_exec(VALUE cls, VALUE rbv_code);
57
- extern VALUE rb_php_vm_get_class(VALUE cls, VALUE rbv_class_name);
62
+ extern VALUE rb_php_vm_exec(VALUE cls, VALUE code);
63
+ extern VALUE rb_php_vm_get_class(VALUE cls, VALUE v_class_name);
58
64
  extern VALUE define_global_constants();
59
65
  extern VALUE define_global_functions();
60
66
  extern VALUE define_global_classes();
@@ -66,13 +72,13 @@ extern VALUE rb_php_global_class_call(VALUE self);
66
72
  extern void php_global_require(char *token, VALUE filepath);
67
73
  extern VALUE rb_php_global_require(VALUE cls, VALUE filepath);
68
74
  extern VALUE rb_php_global_require_once(VALUE cls, VALUE filepath);
69
- extern VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE self);
70
- extern VALUE rb_php_global_print(VALUE self, VALUE arg);
71
- extern VALUE rb_php_global_array(int argc, VALUE *argv, VALUE self);
75
+ extern VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE cls);
76
+ extern VALUE rb_php_global_print(VALUE self, VALUE cls);
77
+ extern VALUE rb_php_global_array(int argc, VALUE *argv, VALUE cls);
72
78
 
73
79
  // class PHPVM::PHPClass
74
- extern VALUE rb_php_class_get(VALUE cls, VALUE rbv_name);
75
- extern VALUE rb_php_class_initialize(VALUE self, VALUE rbv_name);
80
+ extern VALUE rb_php_class_get(VALUE cls, VALUE v_name);
81
+ extern VALUE rb_php_class_initialize(VALUE self, VALUE v_name);
76
82
  extern VALUE rb_php_class_name(VALUE self);
77
83
  extern VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self);
78
84
  extern VALUE rb_php_class_getter(VALUE self);
@@ -96,6 +102,16 @@ extern VALUE rb_php_object_call_magic___call(VALUE self, VALUE name, VALUE args)
96
102
  extern VALUE rb_php_object_call_magic___tostring(VALUE self);
97
103
  extern VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self);
98
104
 
105
+ // class PHPVM::PHPExceptionObject
106
+ extern VALUE rb_php_exception_object_initialize(int argc, VALUE *argv, VALUE self);
107
+
108
+ // class PHPVM::PHPErrorReporting
109
+ extern VALUE rb_php_error_reporting_initialize(int argc, VALUE *argv, VALUE self);
110
+ extern VALUE rb_php_error_reporting_log_message(VALUE self);
111
+ extern VALUE rb_php_error_reporting_error_level(VALUE self);
112
+ extern VALUE rb_php_error_reporting_file(VALUE self);
113
+ extern VALUE rb_php_error_reporting_line(VALUE self);
114
+
99
115
  // module
100
116
  extern void php_vm_module_init();
101
117
  extern void php_vm_module_exit();
@@ -87,33 +87,37 @@ static VALUE zval_to_value_object(zval *z)
87
87
 
88
88
  // class
89
89
  VALUE class = rb_php_class_get(rb_cPHPClass, v_name);
90
+ zend_class_entry *ce = get_zend_class_entry(class);
90
91
 
91
92
  // object
92
93
  VALUE obj = Qnil;
93
94
  if (is_exception_zval(z)) {
94
95
  // exception object
95
96
  zval *z_message = zend_read_property(zend_exception_get_default(TSRMLS_C), z, "message", sizeof("message")-1, 0 TSRMLS_CC);
96
-
97
97
  obj = rb_exc_new2(rb_ePHPExceptionObject, Z_STRVAL_P(z_message));
98
-
99
- rb_iv_set(obj, "php_class", class);
100
98
  } else {
101
99
  // normal object
102
100
  obj = rb_obj_alloc(rb_cPHPObject);
103
-
104
- rb_iv_set(obj, "php_class", class);
105
101
  }
106
102
 
107
103
  // retain
108
104
  Z_ADDREF_P(z);
109
105
 
106
+ // class
107
+ rb_iv_set(obj, "php_class", class);
108
+
110
109
  // resource
111
110
  PHPNativeResource *p = ALLOC(PHPNativeResource);
112
- p->ce = get_zend_class_entry(class);
111
+ p->ce = ce;
113
112
  p->zobj = z;
114
113
  VALUE resource = Data_Wrap_Struct(CLASS_OF(obj), 0, php_native_resource_delete, p);
115
114
  rb_iv_set(obj, "php_native_resource", resource);
116
115
 
116
+ // define php instance properties and methods
117
+ define_php_properties(obj, ce, 0);
118
+ define_php_methods(obj, ce, 0);
119
+ define_php_magic_method(obj, ce, z);
120
+
117
121
  return obj;
118
122
  }
119
123
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php_vm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: php_vm is a native bridge between Ruby and PHP.
15
15
  email: