Hello everytime I try to invite a user or to change the setting for the temporary invitation it says it has a fatal error by a call to an undefined function array_fill_keys() in the temporary_invitartion.module

Comments

ar1000’s picture

the exact thing is happening to me as well. Hope it is fixed soon, this is a cool module, and I want to use it.

ambrielnet’s picture

Yep, same here:
Fatal error: Call to undefined function: array_fill_keys() in O:\www\localvhost-drupal50\sites\all\modules\temporary_invitation\temporary_invitation.module on line 253

ambrielnet’s picture

array_fill_keys is only for PHP 5.2.0 or higher.

One user @ http://php.osuosl.org/manual/en/function.array-fill-keys.php, submitted the following work-around function:

if (! function_exists("array_fill_keys")) {
    function array_fill_keys(array $keys, $value) {
        return array_combine($keys, array_fill(0, count($keys), $value));
    }
} 
ambrielnet’s picture

Okay two things, the function above had a small bug in it. It should be (without the php open and close tags):

if (! function_exists("array_fill_keys")) {
    function array_fill_keys($keys, $value) {
        return array_combine($keys, array_fill(0, count($keys), $value));
    }
}

And this code can be placed in the
temporary_invitation.module
OR
temporary_invitation_api.inc

just paste it at the top, laid out like any other function.

ambrielnet’s picture

array_combine() if for PHP 5, so (http://www.php.net/array_combine):

if (! function_exists("array_combine")) {
    function array_combine($a1,$a2)
    {
        for($i=0;$i<count($a1);$i++)
            $ra[$a1[$i]] = $a2[$i];
        if(isset($ra)) return $ra; else return false;
    }
}   
jpetso’s picture

Thanks, I added both functions to temporary_invitation_api.inc. Please test if it works for you now (either with a CVS checkout or from the 5.x-1.x tarball that will be generated in 12 hours at maximum. If it does, I'm going to push out a new release containing the fixes.

jpetso’s picture

Well, there was no feedback as I would have hoped, but I'll take this as a "yes, it works now". So there's the new 5.x-1.3 release out now, containing these fixes.

jpetso’s picture

Status: Active » Fixed

Oh right, I wanted to close this issue as "fixed". Tada!

the1who’s picture

I don't really want to open up something new about this, but along the array_fil_keys and array_combine, is there a conversion for php4? It'd be really nice since everything else on my site is already in 4 standards and to change everything for a new php version I'm kind of weary about. Plus it's not my server, I just feed off the excess he doesn't use pretty much. So, to save all of the hassles, I was wondering if there is a php4 workaround? I have searched php.net etc for stuff but haven't really turned up a lot, just for array_combine, but not for both. This is why I don't want to create a new hassling thread too, it's rather simple and that there is a question related to array_fill_keys already created here. I'd appreciate it if someone could help me with this!

If it can't be done, I understand. The other invite module doesn't seem to be as feature laid out like this, where it creates the temporary user. That's what I am needing, temporary user, not invite option. Thanks!

-Matt

jpetso’s picture

@the1who: What do you mean, "conversion for PHP 4"? The whole point of this issue is to get Temporary Invitation running on PHP 4, and while I understand that there is a problem, I don't quite get what from your comment what exactly the problem is. Both array_fill_keys() and array_combine() have been included when they are not available (which is the case on PHP 4) so I thought it should already work on PHP 4.

Please provide a more understandable problem report, including:
- the version of Temporary Invitation that you are using
- the exact error message
- optionally, a suggestion how the problem can be fixed.

Temporary Invitation will run on PHP 4, it's only that I won't be the one testing it, that's up to you other ones.

> It'd be really nice since everything else on my site is already in 4 standards and to change everything for a new php version I'm kind of weary about.

In my opinion, this is a bad reason to stay on PHP 4. Better reasons include a) your web host doesn't provide anything else, and/or b) you're working on the conversion to PHP 5, but are not there yet. Staying on PHP 4 for the convenience and the fear of changes will lead you to a situation where your web host switches you whether you want it or not (that time is coming soon, PHP 4 is not being shipped anymore in all current server distribution versions except for Debian, and that one will remove it in its next stable version). PHP 4 is a safe bet for now, but you should try to make it PHP 5 ready as long as you've still got the time to do so.

the1who’s picture

Version: 5.x-1.2 » 5.x-1.3

Ok, I'll try to do the best that I can to follow up on this. When I enable the module, the page returns to the module page and states, "The configuration options have been saved." There is no errors reporting on this page.

I then go to User Management >> Temporary Invitation and I get:

"# warning: array_fill(): Number of elements must be positive in /home/bsarc/public_html/modules/temporary_invitation/temporary_invitation_api.inc on line 35.

# user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation in /home/bsarc/public_html/includes/database.mysql.inc on line 172"

I checked the database, the table wasn't automatically created. I also go to the file and checked line 35 and it shows the php function array_combine: "return array_combine($keys, array_fill(0, count($keys), $value));"

I tried implementing the code work around, but that just made blank pages show up.

I took back-up copy and replaced and it outputs the pages again, went to My Account -> Invitations tab, and this error shows:

"user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation WHERE host_uid = '1' in /home/bsarc/public_html/includes/database.mysql.inc on line 172." Which I'm assuming is from the first instance where there is no table showing up yet for this.

I enter the data into the boxes, I then get the following errors:

"

* user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation WHERE host_uid = '1' in /home/bsarc/public_html/includes/database.mysql.inc on line 172.
* warning: array_fill(): Number of elements must be positive in /home/bsarc/public_html/modules/temporary_invitation/temporary_invitation_api.inc on line 36.
* user warning: Table 'Drupal.temporary_invitation' doesn't exist query: INSERT INTO temporary_invitation (host_uid, invited_uid, name) VALUES ('1', '10', 'Matthew') in /home/bsarc/public_html/includes/database.mysql.inc on line 172.
* user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation WHERE invited_uid = '10' in /home/bsarc/public_html/includes/database.mysql.inc on line 172.
* user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation WHERE invited_uid = '0' in /home/bsarc/public_html/includes/database.mysql.inc on line 172.
* user warning: Table 'Drupal.temporary_invitation' doesn't exist query: SELECT * FROM temporary_invitation WHERE host_uid = '1' in /home/bsarc/public_html/includes/database.mysql.inc on line 172."

So many things there, and I'm assuming all because I'm running php 4. But the account is created and I got user "Temporary user 4hTX66J4-1" showing. I logged into that account to get the settings I predetermined to work. There is the table for login-ticket, which shows more details, such as expiration and uid and passcode. So I'm just trying to understand this a little better.

There are other people that most likely will be taking over this site, as I'm the one developing it for them and our club. For them to see the red boxes as I have, would most likely make them think it doesn't work, even though it does, and they most likely won't use it. Now I'm pretty sure it's going to be because of PHP5 requirement, which I'll do my asking around and seeing if I can get it updated from the 4.3.11 it is running now. I'm limited to what I can and can't do, so I do apologize for this inconvenience if any, just the error boxes are throwing me off and trying to see how I can fix that if I can on PHP4 if able. If not, I understand, seeing if anyone else had experience with this same issue. And sorry for being vague earlier, trying to be, straight to the point without being too confusing.

-Matt

jpetso’s picture

These "database table doesn't exist" errors are not caused by using PHP 4, ...it's just that the {temporary_invitation} table hasn't been installed like it should. After some investigation, I found I had copied the "Engine=InnoDB" part from the Sitepass module, which is baaad, and that may be the reason that it could not be installed, probably your web host has disallowed selecting database engines.

I now removed this in CVS, and put out a new release called 5.x-1.4. Sorry to you and all the other users for messing this up.

the1who, please disable and then uninstall the Temporary Invitation module, afterwards enable it again. With a bit of luck, it should work now.

the1who’s picture

Version: 5.x-1.3 » 5.x-1.4

Thank you for your prompt response and work. This new version got rid of all of the other errors except this one that shows up:

"warning: array_fill(): Number of elements must be positive in /home/bsarc/public_html/modules/temporary_invitation/temporary_invitation_api.inc on line 35."

So kind of wondering what's amiss, if it's us etc, not sure, just posting up. Thanks again!

-Matt

the1who’s picture

ok, so just to add some more to this...

it creates the users, under my account they show up in the invitations tab. i can delete them, and they delete, and I don't get the error messages either related to the UID entry. So that's also benefited, thought I would add that tidbit.

-Matt

jpetso’s picture

Status: Fixed » Active

Aww, how mean from the module that it still doesn't work. Anyways, I'm glad that I at least got the database issue right :)

I plan to take care of the other bug soon (like, in the next few days or so), expect a fix for that as well. If you're all too kind, I would also appreciate if you tell me what action you are executing in order to invoke the remaining error message.

the1who’s picture

I invoke the problem when I go to My Account >> Invitations Tab -> Creating User -> Clicking submit and it will spawn the error message, but also stating the the user is now created in a green box below the red error box, with all the details on how they can log-in and their expiration date etc. The error is the one I posted last, with array_fill and elements being positive. Thanks for your time and efforts and help! Oh, and MODULE =)

ambrielnet’s picture

Yes, besides this warning, everything seems to be working fine.

I get the same warning, but I really haven't much looked into it. My guess is that the array_fill_keys() function provided by the user is not 100% compatible with the version for PHP 5. The function needs to be tweaked a little more to handle diverse scenarios. To debug it on PHP 5, perhaps you can override the php 5 version, or rename the functions in a test copy and make your module point to them, to get the same warning he is speaking of. I would and could, but time is kicking me on so many sides.

jpetso’s picture

Status: Active » Fixed

Given this small hint and the PHP documentation on array_fill(), it was actually a pretty easy bug to resolve. I just put out 5.x-1.6 where this warning is gone, when you read this it should already be downloadable.

Thanks a lot to both of you for your detailed reports, testing and hints on how to get to the core of the issue! That helped a lot, and I hope that Temporary Invitation is now fully compatible to earlier PHP versions where those two annoying functions are not yet included.

Anonymous’s picture

Status: Fixed » Closed (fixed)