Welcome Guest, Not a member yet? Register   Sign In
Declaration of xxx should be compatible with yyy
#1

OK, I just migrated my web app from CI 2.1.4 to CI 3.0.0 and I am now getting a PHP Runtime Notice that shouldn't be related to the upgrade, but nonetheless it's there and I could use some help.

Quote:A PHP Error was encountered
Severity: Runtime Notice
Message: Declaration of Customer:Confusedave() should be compatible with Person:Confusedave(&$person_data, $person_id = false)
Filename: models/Customer.php
Line Number: 243

Here is the context.  Three different times I am extending Person and on methods keeping the base variables, but adding to it.  This means that the save function in Person cannot have the exact same declaration as the classes that extend it.  I would prefer not to just suppress these warnings, but I could use some help getting to the bottom of how to declare these functions so that it doesn't generate the notice.

Customer.php
Code:
class Customer extends Person
{
...
function save(&$person_data, &$customer_data,$customer_id=false)
{
...

Person.php
Code:
class Person extends CI_Model
{
...
function save(&$person_data,$person_id=false)
{
...
Reply
#2

You can't add parameters to an override method.
But you can use func_get_args().
Reply
#3

ok, read up on this and it sounds like even though my code works, there is risk that php gets confused about which function I'm calling and that's why it's throwing the warning. Curious that it does not throw this warning in pre-CI 3.0.0.

It sounds like I have two options. Please correct me if I'm wrong.
I can make the parent function signature include the extra arguments and just make those extra arguments optional arguments.
OR
I can use func_get_args() to pull the extra arguments.

Question: If I go the func_get_args() does the signature have to have no arguments or can I do something like:
Code:
Class Foo
{
function wow(arg1, arg2)
{
}
}

Class Bar extends Foo
{
function wow(arg1,arg2)
{
arg3 = func_get_arg(2);
arg4 = func get arg(3);
}
}

I just couldn't seem to find an example where there were both arguments in the signature and func_get_arg() was used.
Reply
#4

The notices have to do with a change to the error reporting levels in the index.php file. The errors were always there, but they were previously being suppressed.

The CI3 DB_driver actually does something similar to what you're looking for:
PHP Code:
    public function call_function($function)
    {
        
$driver = ($this->dbdriver === 'postgre') ? 'pg_' $this->dbdriver.'_';

        if (
FALSE === strpos($driver$function))
        {
            
$function $driver.$function;
        }

        if ( ! 
function_exists($function))
        {
            return (
$this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
        }

        return (
func_num_args() > 1)
            ? 
call_user_func_array($functionarray_slice(func_get_args(), 1))
            : 
call_user_func($function);
    } 

From this, I would assume that your example would work as expected.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB