--- /dev/null
+--TEST--
+Testing to implement Serializable interface by traits
+--FILE--
+<?php
+
+trait foo {
+ public function serialize() {
+ return 'foobar';
+ }
+ public function unserialize($x) {
+ var_dump($x);
+ }
+}
+
+class bar implements Serializable {
+ use foo;
+}
+
+var_dump($o = serialize(new bar));
+var_dump(unserialize($o));
+
+?>
+--EXPECTF--
+string(20) "C:3:"bar":6:{foobar}"
+string(6) "foobar"
+object(bar)#%d (0) {
+}
}
ce->line_end = zend_get_compiled_lineno(TSRMLS_C);
+
+ /* Check for traits and proceed like with interfaces.
+ * The only difference will be a combined handling of them in the end.
+ * Thus, we need another opcode here. */
+ if (ce->num_traits > 0) {
+ zend_op *opline;
+
+ ce->traits = NULL;
+ ce->num_traits = 0;
+ ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
+
+ /* opcode generation: */
+ opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+ opline->opcode = ZEND_BIND_TRAITS;
+ SET_NODE(opline->op1, &CG(implementing_class));
+ }
if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
&& ((parent_token->op_type != IS_UNUSED) || (ce->num_interfaces > 0))) {
ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
}
- /* Check for traits and proceed like with interfaces.
- * The only difference will be a combined handling of them in the end.
- * Thus, we need another opcode here. */
- if (ce->num_traits > 0) {
- zend_op *opline;
-
- ce->traits = NULL;
- ce->num_traits = 0;
- ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
-
- /* opcode generation: */
- opline = get_next_op(CG(active_op_array) TSRMLS_CC);
- opline->opcode = ZEND_BIND_TRAITS;
- SET_NODE(opline->op1, &CG(implementing_class));
- }
-
CG(active_class_entry) = NULL;
}
/* }}} */