Search code examples
phpclassoopmethodsvbulletin

Method exists but it can't be called


I'm working with vBulletin, and I have to use the vB_datamanger_User class. I've included the right files and the class exists.

I have to use a method called set_userfields, but it doesn't exists (in php opinion). The strange thing is that if I do

$newuser = new vB_DataManager_User($vbulletin,ERRTYPE_ARRAY);
$newuser->set('username',"MyUsername");

It works.

And if I do

var_dump(method_exists($newuser, 'set_userfields'));

It returns bool(true).

But if I do $newuser->set_userfields(array('field12' => 1)); it doesn't work (with no errors).

What am I doing wrong?

EDIT: The method is declared as function set_userfields(&$values, $verify = true, $all_fields = 'normal', $skip_unset_required_fields = false)


Solution

  • If your code looks like this:

    <?php
    
    class vB_DataManager_User{
        public function __construct($a, $b){
        }
    
        function set_userfields(&$values, $verify = true, $all_fields = 'normal', $skip_unset_required_fields = false){
        }
    }
    
    $newuser = new vB_DataManager_User($vbulletin,ERRTYPE_ARRAY);
    $newuser->set_userfields(array('field12' => 1)); // it doesn't work (with no errors).
    

    ... you should be getting this:

    Fatal error: Cannot pass parameter 1 by reference

    If you don't, that means that you haven't enabled full error reporting in your development box. It has nothing to do with methods existence, which would anyway trigger an error as well:

    Fatal error: Call to undefined method vB_DataManager_User::not_valid()