I guess this is very minor stuff, but anyway...

If the mbstring extension is loaded, the call to strrpos() in [...]/includes/menu.inc on line 910 will give a warning: mb_strrpos(): Empty haystack in [...]\includes\menu.inc on line 910. This will output sometimes (e.g. when saving the theme selection in the admin area) before headers are sent producing thus additional errors. On other occurrences it will simply appear at the top of the page.

The problem is easily solved by not using the mbstring extension in PHP, which anyway is not set by default.

Tried on Windows XP + Apache 2.0.49 + PHP 4.3.2 + Drupal 4.5.0

CommentFileSizeAuthor
#8 menu_mbstring.diff973 bytesRichard Archer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vitamin-1’s picture

That's because mbstring doesn't like empty arguments.
The fix is described here (in russian), thanks to Basielienis: http://drupal.ru/node/view/310
Shortly, you should search in menu.inc (line 910 in 4.5.0) and replace line

$parent = substr($parent, 0, strrpos($parent, '/'));

with

if ($parent) $_lenght = strrpos($parent, "/");
$parent = substr($parent, 0, $_lenght);

ps: Can anybody commit this in HEAD?

Uwe Hermann’s picture

This looks a bit strange to me (I haven't tested it though). Isn't $_length uninitialized if $parent is non-empty?Is that desired? If yes, though it may work, it's not a very obvious or clean solution, IMHO.

Anonymous’s picture

I had this same issue. The solution for me was to revert back to default values on a setting I had changed in my /etc/php.ini. My php.ini included
mbstring.func_overload = 7
after resetting it back to the default value
mbstring.func_overload = 0
drupal as once again happy.

I had set that value to 7 at the suggestion of eGroupWare, to allow support for utf extended characters (if I understood it correctly).

Hope that helps--
rob@shrouded.net

vitamin-1’s picture

Yes, but disabling function overload you disable using unicode aware string functions in php.
As a result, you loose case insensetive searching in languages other than English.
AFAIR, drupal doesn't use mbstring extension directly, so the only way for non-english speaking people to use full functional searching is to enable function overloading, so strrpos() is automagically replaced with mb_strrpos(), ereg() with mb_ereg() etc.
I hope that one day somebody of developers will fix this annoying bug..

Steven’s picture

This won't be fixed unless there is a clear description of the problem and its solution, which complies with the Drupal coding standards.

enarsson’s picture

Well, I am competely new to Drupal, and this error was part of my first impression. It should be fixed as mbstring extension should not need to interfere with Drupal and the problem is there in 4.6.0 as well. My host has this extension on by default.

As far as I can understand, strrpos gets replaced with mb_strrpos by the mbstring extension (http://php.net/manual/en/ref.mbstring.php) and mb_strrpos doesn't like the empty haystack unlike strrpos (at least in php4).

So the current code (line 973-976) in version 4.6.0 is

      do {
        $parent = substr($parent, 0, strrpos($parent, '/'));
      }
      while ($parent && !array_key_exists($parent, $_menu['path index']));

and could be replaced with

      do {
        $parent = substr($parent, 0, strrpos($parent, '/'));
      }
      while (($parent || $parent!="") && !array_key_exists($parent, $_menu['path index']));

There might be better and more logical solutions to this problem, but this at least seams to fix it for me.

Steven’s picture

Status: Active » Closed (won't fix)

Drupal 4.7 has a unicode layer which deals with mbstring. Note however that function overloading is optional for mbstring, and explicitly unsupported in Drupal. Drupal now instructs you in how to fix a broken mbstring setup.

Richard Archer’s picture

Version: » 4.6.3
Status: Closed (won't fix) » Reviewed & tested by the community
FileSize
973 bytes

This problem makes the theme settings unusable if mb_strrpos is active and I think it should be fixed in all supported versions of Drupal. Including HEAD because even if mb_string overloading is enabled that is no excuse for throwing these warnings.

The solution is to wrap the do..while in an if to make sure the loop body is not executed if $item['path'] is empty. Which happens every time the menu tree is built when root is processed.

Here's a patch which applies with various offsets against all Drupals from 4.5 to HEAD.

Dries’s picture

I wonder why $item['path'] is empty to begin with ... is that the correct/expected behavior?

Richard Archer’s picture

Menu item 0 always has a blank path. So one warning is thrown every time the menu is built.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD, DRUPAL-4-6 and DRUPAL-4-5. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)
beate_r’s picture

Version: 4.6.3 » 4.7.3
Priority: Minor » Normal
Status: Closed (fixed) » Active

to make things short: it appears to have reappeared in 4.7.3. Still the requirements are in conflict to those of egroupware (and probably phpgroupware as well).

Why is it so hard to fix this permanently?

best wishes

Beate

beate_r’s picture

Status: Active » Closed (fixed)

please excuse, i just noticed that the problem seems to be a missing fix in the taxonomy_menu module. So i reported it in the wrong place.