Menu

#1338 Cannot instantiate abstract class base

None
closed-fixed
php (58)
5
2021-12-29
2013-09-30
No

I am getting the following error:

$ php -d enable_dl=On test.php
PHP Fatal error: Cannot instantiate abstract class base in demo.php on line 100

swig generates:

static function create_concrete($b=true) {
    $r=base_create_concrete($b);
    if (!is_resource($r)) return $r;
    switch (get_resource_type($r)) {
    case '_p_base': return new base($r);
    default: return new base($r);
    }
}

for the following input C++:

struct base
{
 virtual void foo() = 0;
 static base * create_concrete(bool b = true);
};

Full example is at:
https://github.com/malaterre/PublicRep/tree/master/SWIG/virtualbase

Discussion

  • Olly Betts

    Olly Betts - 2013-12-12
    • labels: --> php
    • assigned_to: Olly Betts
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2021-12-29
    • status: open --> closed-fixed
     
  • Olly Betts

    Olly Betts - 2021-12-29

    This is fixed in git master, presumably by the rewrite to use PHP's C API to create classes instead of generating a .php script which defines them.

    The test needs adjusting to remove require_once( 'demo.php' ); (as that file no longer gets generated at all) and then the output is now:

    $ php7.4 -d extension=~+/demo.so test.php
    blaconcrete::foo
    toto3
    

    (PHP resources are no longer used by SWIG in the generated wrapper code, so the is_resource() checks in your test code will all be false now.)

    This work will be in PHP 4.1.0.

     

Log in to post a comment.

MongoDB Logo MongoDB