|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69691 ::class behaviour inside assertion
Submitted: 2015-05-22 09:09 UTC Modified: 2015-05-22 11:57 UTC
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: red dot led0 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: red dot led0 at gmail dot com
New email:
PHP Version: OS:


 [2015-05-22 09:09 UTC] red dot led0 at gmail dot com
'MyClass::class' construction works different inside and outside of assertion if namespace given.

Test script:

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:
string(6) "Test\A"
string(6) "Test\A"
string(6) "Test\B"
string(6) "Test\B"

Actual result:
string(6) "Test\A"
string(1) "A"
string(6) "Test\B"
string(1) "B"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-22 11:57 UTC]
-Status: Open +Status: Not a bug
 [2015-05-22 11:57 UTC]
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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 31 20:03:38 2023 UTC