Fatal error: Call to undefined function token_get_all()
rek2 - January 24, 2008 - 21:02
| Project: | Translation template extractor |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
php potx-cli.php
Processing potx.module...
Fatal error: Call to undefined function token_get_all() in /var/www/dailyradical.org/htdocs/sites/all/modules/potx/potx.inc on line 123
Help?

#1
Well, you need at least PHP 4.2.0 to use potx, but Drupal itself has a higher requirement, so I don't know how do you experience this error. What's your PHP version?
#2
I get this error, too. At first I thought it was because token was not installed. After installing token I learned that it does not define a function token_get_all. Both potx and coder call token_get_all, but it's not defined anywhere.
Attached patch adds a dependency on token, but does not solve this problem.
#3
D'oh! I'm catching on now. token_get_all is defined by PHP. Confusing.
But you have to compile PHP with token support: http://us.php.net/manual/en/ref.tokenizer.php
So this is probably a configuration issue. If I can get potx to display a friendlier error message, I'll attach another patch...
#4
This is not perfect, because the error only appears after a submit (it would be better to warn sooner). But it's better than the current behavior.
#5
Dave, token_get_all() has nothing to do with the Drupal token module. It is PHP's built in function: http://php.net/token_get_all So your patch would not help anything. In fact, since potx does not use token module, it would be plain wrong.
The PHP documentation does not mention any cases when the tokenizer in not compiled into PHP, but you might need to look for this extension in your distribution (I'd expect you are on some Linux server, since Windows and Mac builds certainly include this). I found some evidence that some distros need the php-tokenizer package installed separately for PHP. See: http://rpmfind.net/linux/rpm2html/search.php?query=php-tokenizer for example
Let us know if this solved the problem for you, so I can add some docs, and possibly some check to the module which warns about this requirement.
#6
Gabor,
I think d.o caching is keeping us out of sync. I figured out that token_get_all comes from PHP, but you didn't see my most recent comments on this thread.
Anyway, the patch #4 above takes 'token' out of the dependencies, and produces a better error message when PHP's tokenizer is not found.
I recompiled PHP (using the tokenizer use flag on gentoo) and potx now works correctly. Thanks!
#7
I see this as well. I have configured my system to build my PHP with Tokenizer now, but want to test this before I do that. However, just by looking at the patch, I see some flaws:
$Id$(which should be in all files) and adds two empty lines?? Needs to go.I'll go make a re-roll and test that.
#8
I'm still getting it on running cron, during which l10n_server calls potx and thus makes potx call
token_get_all(). So I'm thinking the check needs to go into another part of the code, thanpotx_select_form_validate().But for now, the revised patch from before has been attached. (I'm also not so fond of the wording. Perhaps or at least something a bit more verbose/descriptive than the current text. Gábor?)
#9
- We don't needs to break the form_set_error() to multiple lines!
- I'd say
The <a href="%tokenizer">PHP tokenizer functions</a> are required.#10
Here's a hand-edited re-roll based on Gábor's comments.
@Gábor: Did you really mean
%tokenizerand not@tokenizer?I also still believe this check should go somewhere else in the code, to catch other modules' taking advantage of potx, thus triggering the error.
#11
hass suggested on similar issues to just use hook_requirements(). I've declined his suggestion quite a few times, since it does not enforce that you would not be able to install the module in Drupal 5 (it does enforce it in Drupal 6). Since nagging the users on the requirements screen is generally the better practice, I've implemented this as a hook_requirements() check in Drupal 6.x-2.x and will backport it to 5.x when I get around to it.
Committed this completely new potx.install file to CVS.
#12
Suggestion in case you face the same initial error:
check that you don't have multiple versions of PHP installed. The one available at the command line may not be the one used for the website....
Or the php.ini file may not be the one that should apply to your php version (Windows for example may have a few old ones in different places...)
#13
PHP tokenizer is a requirement for Drupal 7.x now that the registry uses it. See #315901: Add server capabilities check to installation/upgrade tasks http://drupal.org/node/315901#comment-1518374
#14
@dropcube: indeed, the .install file was even removed in the D7 module to accomodate for this.
Since 5.x is not maintained, moving back to fixed.
#15
Automatically closed -- issue fixed for 2 weeks with no activity.