Mantis - Quercus
Viewing Issue Advanced Details
1180 minor always 06-05-06 18:09 06-09-06 15:57
koreth  
ferg  
normal  
closed 3.0.20  
fixed  
none    
none 3.0.20  
0001180: Need is_subclass_of()
PHP:

<?php
if (is_subclass_of('a', 'b')) { print "yep\n"; }
?>

This fails under Quercus:

Users/sgrimm/resin/resin/webapps/test/test.php:2: Fatal Error: Users/sgrimm/resin/resin/webapps/test/test.php:2: 'is_subclass_of' is an unknown function.

Notes
(0001267)
koreth   
06-05-06 18:58   
Here's an implementation (which I put in ClassesModule) that seems to work.

  /**
   * Returns true if one class is a subclass of another.
   */
  public static boolean is_subclass_of(Env env,
                             @ReadOnly Value value,
                             @ReadOnly String className)
  {
    QuercusClass clazz;
    if (value instanceof Var) {
      Var var = (Var) value;
      value = var.getRawValue();
    }
    if (value instanceof StringValue) {
      StringValue str = (StringValue) value;
      clazz = env.findClass(str.toString());
    }
    else if (value instanceof ObjectValue) {
      ObjectValue obj = (ObjectValue) value;
      clazz = obj.getQuercusClass();
    }
    else {
      return false;
    }
    while ((clazz = clazz.getParent()) != null) {
      if (clazz.getName().equals(className))
    return true;
    }
    return false;
  }
(0001278)
ferg   
06-09-06 15:57   
php/1j0c