--- /dev/null
+--TEST--
+Bug #37811 define not using toString on objects
+--FILE--
+<?php
+
+class TestClass
+{
+ function __toString()
+ {
+ return "Foo";
+ }
+}
+
+define("Bar",new TestClass);
+var_dump(Bar);
+define("Baz",new stdClass);
+var_dump(Baz);
+
+?>
+===DONE===
+--EXPECTF--
+string(3) "Foo"
+
+Warning: Constants may only evaluate to scalar values in %sbug37811.php on line %d
+
+Notice: Use of undefined constant Baz - assumed 'Baz' in %sbug37811.php on line %d
+string(3) "Baz"
+===DONE===
+--UEXPECTF--
+unicode(3) "Foo"
+
+Warning: Constants may only evaluate to scalar values in %sbug37811.php on line %d
+
+Notice: Use of undefined constant Baz - assumed 'Baz' in %sbug37811.php on line %d
+unicode(3) "Baz"
+===DONE===
Define a new constant */
ZEND_FUNCTION(define)
{
- zval **var, **val, **non_cs;
+ zval **var, **val, **non_cs, *val_free = NULL;
int case_sensitive;
zend_constant c;
break;
}
+repeat:
switch (Z_TYPE_PP(val)) {
case IS_LONG:
case IS_DOUBLE:
case IS_RESOURCE:
case IS_NULL:
break;
+ case IS_OBJECT:
+ if (!val_free) {
+ if (Z_OBJ_HT_PP(val)->get) {
+ val_free = *val = Z_OBJ_HT_PP(val)->get(*val TSRMLS_CC);
+ goto repeat;
+ } else if (Z_OBJ_HT_PP(val)->cast_object) {
+ ALLOC_INIT_ZVAL(val_free);
+ if (Z_OBJ_HT_PP(val)->cast_object(*val, val_free, UG(unicode)?IS_UNICODE:IS_STRING TSRMLS_CC) == SUCCESS) {
+ val = &val_free;
+ break;
+ }
+ }
+ }
+ /* no break */
default:
zend_error(E_WARNING,"Constants may only evaluate to scalar values");
+ if (val_free) {
+ zval_ptr_dtor(&val_free);
+ }
RETURN_FALSE;
- break;
}
if (Z_TYPE_PP(var) != (UG(unicode)?IS_UNICODE:IS_STRING)) {
c.value = **val;
zval_copy_ctor(&c.value);
+ if (val_free) {
+ zval_ptr_dtor(&val_free);
+ }
c.flags = case_sensitive; /* non persistent */
if (Z_TYPE_PP(var) == IS_UNICODE) {
c.name.u = zend_ustrndup(Z_USTRVAL_PP(var), Z_USTRLEN_PP(var));