Skip to content Skip to sidebar Skip to footer

Fatal Error: Uncaught Argumentcounterror: Too Few Arguments To Function Admincategory::deletecategory(),

I know there were some questions related to this, but there are c ++ or other languages. I get this error and I'm not sure what's wrong with my function. This is my Error Fatal er

Solution 1:

Sometimes it happen that AdminCategory::deletecategory($parentId) is called without a parameter but prototype do not have a default value for it and therefore exception is thrown. Since you get data from a post request and there is always a possibility that a category do not have a parent you can refactor your method to looks like:

functiondeletecategory($parentId = null)
{
    $ids = $_POST['id'];
    $this->model->deletecategory($ids);
    if (null !== $parentId) {
        header('location:'.URL.'admincategory/showchildren/'.$parentId);
    }
    // PUT MORE OF YOUR LOGIC HERE, I DO NOT KNOW WHAT SHOULD HAPPEN
}

If you are using typing hints more appropriate would be to make method looks like

functiondeletecategory(string$parentId = ''): void //voidisforphp7.1
 {
    $ids = $_POST['id'];
    $this->model->deletecategory($ids);
    if ('' !== $parentId) {
        header('location:'.URL.'admincategory/showchildren/'.$parentId);
    }
    // AGAIN LOGIC HERE
 }

If you REALLY expect that parentId MUST be passed then instead wrap method caller with try catch

if (method_exists($object, $this->method)) {
    try {
        call_user_func_array([$object, $this->method], $this->params);
    } catch (\Exception$ex) {
        // HANDLE EXCEPTION HERE
    }
}

Post a Comment for "Fatal Error: Uncaught Argumentcounterror: Too Few Arguments To Function Admincategory::deletecategory(),"