matjazp Posted November 4, 2016 Share Posted November 4, 2016 <?php // in mytemplate.php echo "Roles:" . wireClassExists('Roles') . "<br>"; // expecting true echo "foo:" . wireClassExists('foo') ."<br>"; // expecting false class bar extends Roles { } echo "bar: " . wireClassExists('bar') ."<br>"; //expecting true Output: Roles:1 foo: bar: If I add namespace ProcessWire in mytemplate.php, then the result is as expected, class bar exists: <?php namespace ProcessWire; // in mytemplate.php echo "Roles:" . wireClassExists('Roles') . "<br>"; // expecting true echo "foo:" . wireClassExists('foo') ."<br>"; // expecting false class bar extends Roles { } echo "bar: " . wireClassExists('bar') ."<br>"; //expecting true Output: Roles:1 foo: bar: 1 This is how it should be? 1 Link to comment Share on other sites More sharing options...
horst Posted November 4, 2016 Share Posted November 4, 2016 Interesting question! I give a like for it. OT: I always would use namespaced template files for new projects now. (Skipping all filecompiler interaction for template files) 2 Link to comment Share on other sites More sharing options...
kixe Posted November 4, 2016 Share Posted November 4, 2016 The Function wireClassExists() is described as follows: ProcessWire namespace aware version of PHP's class_exists() function The function returns the expected value, without a defined namespace <?php class bar extends Roles { } // namespace aware function var_dump(wireClassExists('bar')); // return false var_dump(wireClassExists('\bar')); // return true // not namespace aware function var_dump(class_exists('bar')); // return true and with defined namespace <?php namespace ProcessWire; class bar extends Roles { } // namespace aware function var_dump(wireClassExists('bar')); // return true var_dump(wireClassExists('\bar')); // return false // not namespace aware function var_dump(class_exists('bar')); // return false 6 Link to comment Share on other sites More sharing options...
matjazp Posted November 4, 2016 Author Share Posted November 4, 2016 Thx, kixe. I wrongly expected that wireClassExists('bar') would always return true, with or without namespace. Because this is not the case, this is why DynamicRoles module (and possible others?) doesn't work on PW3 unless you add namespace. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now