Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-09-08 06:15:03

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Problem with Textpattern 4.0.5 + PHP 5.2.4

Not sure if this is the right place to post this. But I have discovered a very strange bug that occurs when running Textpattern 4.0.5 under PHP 5.2.4. It may occur with previous versions of Textpattern, but I have not tried to reproduce it with any version other than 4.0.5.

The bug occurs when an article uses textile to create a list. For example:

# Item 1 # Item 2 # Item 3 # Item 4

will create the following html:

<ol> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ol> <ol> <li>Item 4</li> </ol>

Notice that the final item gets placed into it own list. For any list of n items, the nth item gets placed into its own list.

I don’t know if this is a Textpattern bug or a problem in PHP 5.2.4, but when I reverted my installation of PHP back to 5.2.3 the problem disappeared.

Offline

#2 2007-09-08 13:54:32

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Thanks for reporting that it occurs only in PHP 5.2.4.
I think I know what’s causing this. Interesting change in behaviour of the next function in PHP.

Last edited by ruud (2007-09-08 14:02:35)

Offline

#3 2007-09-08 14:55:00

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Can you put this in a test.php file and tell me what it shows in 5.2.3 (I’ve already tested in 5.2.4):

<?php

$chars = array('a', 'b', 'c', 'd', 'e');

foreach($chars as $char)
{
  $chars1   .= $char;
  $cur_pre  .= current($chars);
  $next     .= next($chars);   
  $cur_post .= current($chars);
}

echo "
chars         : $chars1     
current (pre) : $cur_pre
next          : $next
current (post): $cur_post
";

reset($chars);

foreach($chars as $char)
{
  $chars2  .= $char;
  $current .= current($chars);
}

echo "
chars  : $chars2    
current: $current
";

?>

Offline

#4 2007-09-08 15:25:42

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Nevermind, I found a test machine with PHP 5.2.3 as well.

5.2.3 gives:

chars         : abcde
current (pre) : abcde
next          : bcde
current (post): bcde

chars  : abcde
current: aaaaa

5.2.4 gives:

chars         : abcde
current (pre) : bcde
next          : cde
current (post): cde

chars  : abcde
current: bbbbb

I’m not sure if that’s a regression in PHP or if we’re just using ‘next’ inappropriately, so I’m filing a bug report with PHP to make sure.

You can work around the problem, by replacing these two lines (in the fList function in /textpattern/lib/classTextile.php):

foreach($text as $line) {
  $nextline = next($text);

with:

foreach($text as $nr => $line) {
  $nextline = isset($text[$nr+1]) ? $text[$nr+1] : false;

Last edited by ruud (2007-09-08 15:28:45)

Offline

#5 2007-09-08 15:39:08

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Thanks. I had a feeling this was due to some change in PHP’s underlying array-handling functions.

Offline

#6 2007-09-08 16:59:43

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Looks like PHP devs consider this inappropriate usage, see bug #42306, so I’ll fix this in classTextile as shown in my earlier post.

Fixed in SVN changeset 2640

Last edited by ruud (2007-09-08 17:09:29)

Offline

#7 2007-09-08 20:37:15

Logoleptic
Plugin Author
From: Kansas, USA
Registered: 2004-02-29
Posts: 482

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

Thanks for your help on this, Ruud. I spotted this bug while doing some work on artagesw’s website, and was completely baffled by it. I’m glad to see there’s been a resolution, especially since my own host is moving to PHP 5.2.4 soon.

What’s the likelihood of seeing this fixed in a 4.0.5.1 release, so people don’t have to make source changes with each new installation or keep a patched zip file of their own?

Offline

#8 2007-09-08 20:42:05

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

There won’t be a 4.0.5.1, but there will certainly be a 4.0.6 release, preferably within weeks rather than months.

Offline

#9 2007-09-08 20:59:26

Logoleptic
Plugin Author
From: Kansas, USA
Registered: 2004-02-29
Posts: 482

Re: Problem with Textpattern 4.0.5 + PHP 5.2.4

ruud wrote:

There won’t be a 4.0.5.1, but there will certainly be a 4.0.6 release, preferably within weeks rather than months.

That would be awesome. Especially the “within weeks” part. :-)

Offline

Board footer

Powered by FluxBB