Bug #69691 [Opn->Nab]: ::class behaviour inside assertion
Edit report at https://bugs.php.net/bug.php?id=69691&edit=1
ID: 69691
Updated by: nikic@php.net
Reported by: red dot led0 at gmail dot com
Summary: ::class behaviour inside assertion
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.6.9
Block user comment: N
Private report: N
New Comment:
String asserts have scoping equivalent to eval(). Among other things, this means that they have
their own namespace context - they do not share the namespace or import list of the context they
occur in.
If you want to stay in the same context, don't use strings and pass your expression directly.
In PHP 7 this will incur no cost if asserts are disabled.
Previous Comments:
------------------------------------------------------------------------
[2015-05-22 09:09:57] red dot led0 at gmail dot com
Description:
------------
'MyClass::class' construction works different inside and outside of assertion if namespace
given.
Test script:
---------------
<?php
namespace Test; // Without namespace works fine
assert_options(ASSERT_ACTIVE, 1);
class A { }
class B extends A { }
$test1 = $test2 = $name_a = $name_b = null;
$test1 = is_subclass_of(B::class, A::class);
assert('($test2 = is_subclass_of(B::class, A::class)) || 1');
assert('($name_a = A::class) || 1');
assert('($name_b = B::class) || 1');
var_dump($test1, $test2);
var_dump(A::class, $name_a);
var_dump(B::class, $name_b);
Expected result:
----------------
bool(true)
bool(true)
string(6) "Test\A"
string(6) "Test\A"
string(6) "Test\B"
string(6) "Test\B"
Actual result:
--------------
bool(true)
bool(false)
string(6) "Test\A"
string(1) "A"
string(6) "Test\B"
string(1) "B"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69691&edit=1
Thread (2 messages)