This Help forum is for issues relates to the latest release (1.2.x). For issues related to beta or svn version please use their own Help forum.
When requesting help please provide as much information as possible. Explain what version of webtrees, PHP and MYSQL you are using. If possible provide a URL to your site so we can see the problem first-hand.
Tip: Think about putting these details in your signature, so it appears in the footer of ALL your messages
  • Page:
  • 1

TOPIC:

PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #1

  • apn
  • apn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 50
Dears,

I just upgraded my server to php 5.4 and something goes wrong now in the print_chart_by_decade function:

Error message:
ERROR 8: String offset cast occured
0 Error occurred on line 2015 of file functions_print_lists.php in function print_chart_by_decade
1 called from line 427 of file functions_print_lists.php in function format_indi_table
2 called from line 154 of file mediaviewer.php

Code:
2014         for ($y=1570; $y<2030; $y+=10) {
2015                 $chart_url .= $CHART_ENCODING61[floor(substr_count($data[$y], "M")*61/$vmax)];
2016         }

Demonstration here:
genealogie.deprelledelanieppe.be/mediavi...000&ged=prellenieppe

Does anybody already fixed this issue or shall I investigate?

Best Regards,
Arnaud.
webtrees 1.7.11 at genealogie.deprelledelanieppe.be
FreeBSD 11.2-RELEASE-p4, nginx-1.14.1, apache24-2.4.37, php72-7.2.11, mariadb101-server-10.3.10
Intel(R) Core(TM) i5-3570S CPU @ 3.10GHz 4 cores / 16GB RAM

Please Log in or Create an account to join the conversation.

Last edit: by apn.

Re: PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #2

  • apn
  • apn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 50
I just disabled the three calls in order not to have these errors being shown on my prod website:
427                 //print_chart_by_decade($birt_by_decade, WT_I18N::translate('Decade of birth')).
 428                 '</td><td>'.
 429                 //print_chart_by_decade($deat_by_decade, WT_I18N::translate('Decade of death')).
 430                 '</td></tr><tr><td colspan="2">'.
 431                 //print_chart_by_age($deat_by_age, WT_I18N::translate('Age related to death year')).

I don't know what exactly has been disabled but I can't see any difference in the page output.

PS: statistics.php is also impacted by this "String Offset cast occured":
genealogie.deprelledelanieppe.be/statist...php?ged=prellenieppe
ERROR 8: String offset cast occured
0 Error occurred on line 3943 of file Stats.php in function _array_to_extended_encoding
1 called from line 675 of file Stats.php in function chartSex
2 called from line 84 of file statistics.php
webtrees 1.7.11 at genealogie.deprelledelanieppe.be
FreeBSD 11.2-RELEASE-p4, nginx-1.14.1, apache24-2.4.37, php72-7.2.11, mariadb101-server-10.3.10
Intel(R) Core(TM) i5-3570S CPU @ 3.10GHz 4 cores / 16GB RAM

Please Log in or Create an account to join the conversation.

Last edit: by apn.

Re: PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #3

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 14491
I don't (yet) have PHP5.4 - I'm still using 5.3.10

The first error is probably this line in print_chart_by_decade()

$chart_url .= $CHART_ENCODING61[floor(substr_count($data[$y], "M")*61/$vmax)];

As far as I understand, the error <<String Offset cast occured>> means that the expression <<floor(substr_count($data[$y], "M")*61/$vmax>> is not an integer.

It looks like it will always generate an integer. Can you investigate this for me?

The second problem is similar. It is this line in _array_to_extended_encoding() Stats.php

$encoding .= self::$_xencoding[$first].self::$_xencoding[$second];

Again, $first and $second should always be integers.

After you have investigated, please raise a bug report. Thanks.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #4

  • apn
  • apn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 50
Hi fisharebest,

Indeed, you're right, it works perfectly now.

Here are my hacks (To be validated):
# diff includes/functions/functions_print_lists.php.bogus includes/functions/functions_print_lists.php
2015c2015
< 		$chart_url .= $CHART_ENCODING61[floor(substr_count($data[$y], "M")*61/$vmax)];
---
> 		$chart_url .= $CHART_ENCODING61[(int)floor(substr_count($data[$y], "M")*61/$vmax)];
2019c2019
< 		$chart_url .= $CHART_ENCODING61[floor(substr_count($data[$y], "F")*61/$vmax)];
---
> 		$chart_url .= $CHART_ENCODING61[(int)floor(substr_count($data[$y], "F")*61/$vmax)];
# diff library/WT/Stats.php.bogus library/WT/Stats.php
3941c3941
< 			$first = floor($value / 64);
---
> 			$first = (int)floor($value / 64);
webtrees 1.7.11 at genealogie.deprelledelanieppe.be
FreeBSD 11.2-RELEASE-p4, nginx-1.14.1, apache24-2.4.37, php72-7.2.11, mariadb101-server-10.3.10
Intel(R) Core(TM) i5-3570S CPU @ 3.10GHz 4 cores / 16GB RAM

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #5

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 14491
Using the (int) simply hides the error.

I want to know what non-integer values are being generated.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 9 years 1 month ago #6

  • apn
  • apn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 50
All values returned were integers but of type float.

So it seems safe to cast into (int) as the return value of floor() will always be an integer:
php.net/manual/en/function.floor.php

I enabled a var_dump on the variable $first in Stats.php, here is (part of) the output:
float(0)
ERROR 8: String offset cast occured
0 Error occurred on line 3944 of file Stats.php in function _array_to_extended_encoding
1 called from line 675 of file Stats.php in function chartSex
2 called from line 84 of file statistics.php
float(31)
ERROR 8: String offset cast occured
0 Error occurred on line 3944 of file Stats.php in function _array_to_extended_encoding
1 called from line 675 of file Stats.php in function chartSex
2 called from line 84 of file statistics.php
float(32)
ERROR 8: String offset cast occured
0 Error occurred on line 3944 of file Stats.php in function _array_to_extended_encoding
1 called from line 675 of file Stats.php in function chartSex
2 called from line 84 of file statistics.php
webtrees 1.7.11 at genealogie.deprelledelanieppe.be
FreeBSD 11.2-RELEASE-p4, nginx-1.14.1, apache24-2.4.37, php72-7.2.11, mariadb101-server-10.3.10
Intel(R) Core(TM) i5-3570S CPU @ 3.10GHz 4 cores / 16GB RAM

Please Log in or Create an account to join the conversation.

Last edit: by apn.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #7

Little late to this party, but I, too, encountered this error after upgrading to PHP 5.4.

Arnaud's solution worked for me. "intval(floor(...))" could be used in lieu of the cast.

@Greg - Didn't see a bug report, do you still need one?
Norm

Debian Sid
PHP 7.0.14-2
Mysql 5.7.16-1 (Debian)
Apache/2.4.25 (Debian)

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #8

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 14491
You don't say what version of webtrees you are using, so I guess you are using 1.2.7. In this case, the bugs have already been fixed. But if you are seeing this error in the latest SVN build, then please report the bug.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

Do you need a web hosting solution for your webtrees site?
If you prefer a host that specialises in webtrees, the following page lists some suppliers able to provide one for you: 

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #9

I just upgraded to v. 1.3.0 svn13941 and still see the errors when selecting families or individuals on the lists tab.

I'll file a bug report.
Norm

Debian Sid
PHP 7.0.14-2
Mysql 5.7.16-1 (Debian)
Apache/2.4.25 (Debian)

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #10

J'observe la même erreur sur mon site quand on essaie les fonctions de recherche… Mais je suis incapable d’expliquer ça en anglais !

Google translator:
I see the same error on my site when I try the search function ... But I am unable to explain it in English!
Poèmes et chansons pour les cinq saisons
www.astre.tk

Please Log in or Create an account to join the conversation.

Last edit: by Jackie.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #11

  • fisharebest
  • fisharebest's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 14491
@astre

Which version of webtrees?

I believe that this problem is fixed in the latest (SVN) code.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #12

  • ToyGuy
  • ToyGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Live like it's Christmas every day - Santa Stephen
  • Posts: 4925
@greg, @astre
YES, this bug was squashed in SVN-13943, at least when using PHPv5.4.3
OUI, ce bug a été écrasée dans le SVN-13943, au moins lors de l'utilisation PHPv5.4.3
Santa Stephen the Fabled Santa
Latest webtrees at MyArnolds.com
Hosted by webtreesonline.com , a division of GeneHosts LLC
MacOS 10.6.8, Apache 2.2+, PHP 5.4.16, MySQL 5.5.28

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #13

Bonjour et merci.
Je suis bien en PHP 5.4.3 (d'après mon hébergeur), webtrees 1.2.7 ; mais pour le SVN-13943, je ne sais pas ce que c'est !
Vous pouvez voir ça sur < astre.legtux.org/desastre/ >
Amicalement
Poèmes et chansons pour les cinq saisons
www.astre.tk

Please Log in or Create an account to join the conversation.

Re: PHP 5.4 : ERROR 8: String offset cast occured 8 years 11 months ago #14

  • kiwi
  • kiwi's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 4986
Astre, you must wait for the next release of webtrees.

Vous devez attendre la prochaine version de webtrees
Nigel

www.our-families.info

Hosted at:
Follow me at:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum