0

When i try and activate my custom plugin i get the error shown below but this makes no sense to me as it seems ok code wise.

Fatal error: Class 'Functionality\AlterTable\AlterTableComments' not found in C:\wamp64\www\wp-content\plugins\functionality\example.php on line 130

incase your wondering this is on line 130:

new AlterTableComments;
4
  • This simply means the class you are trying to initiate is not defined. Did you write the plugin yourself?
    – Johansson
    Apr 18, 2018 at 18:47
  • try to use class name with namespace prefix $a = '\namespacename\classname'; $obj = new $a; see php.net/manual/en/language.namespaces.dynamic.php Apr 19, 2018 at 6:14
  • $a = '\PethouseukFunctionality\AlterTable\AlterTableComments'; $obj = new $a; Apr 19, 2018 at 9:11
  • Add code snippet to your question if possible. Apr 19, 2018 at 9:57

1 Answer 1

0

What I conclude form your comments is pethouseuk-functionality.php

include 'AlterTableComments.php';

use PethouseukFunctionality\AlterTable;

$a = 'PethouseukFunctionality\AlterTable\test';
$a();  // function call

$b = 'PethouseukFunctionality\AlterTable\AlterTableComments';
$c = new $b; // new object

$c->yourfunction('test'); // Method call

Another file AlterTableComments.php

<?php

namespace PethouseukFunctionality\AlterTable;

interface AlterTableInterface{

    function yourfunction($param);

}

class AlterTableComments implements AlterTableInterface{
    function yourfunction($param){
        var_dump($param);
    }
}

function test(){
    echo 'this is test ';
}

Result: this is test string(4) "test"

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.