Jump to content


Function split() is deprecated


14 replies to this topic

#1 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 15 July 2009 - 03:01 PM

I've just installed WampServer locally and copied one of my sites across for major surgery. (etomite v1.1)
I'm using the latest packaged WampServer download and after a few minor problems (the documentation isn't much use) I finally managed to get it to try to start up the site, only to receive this error

Quote

Etomite encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »

PHP error debug
Error: Function split() is deprecated
Error type/ Nr.: - 8192
File: C:\wamp\www\efikim\index.php
Line: 557
Line 557 source: $tempSnippetParams = split($splitter, $tempSnippetParams);

I'm a little surprised that using a deprecated function causes it to give an error - maybe there's a configuration option for php I need to set?

On the other hand, if it is deprecated, maybe its time to consider changes to the code, as others may be hit by this too on 'real' hosts in future.

versions in the current Wampserver download are:
MySQL 5.1.136
PHP 5.3.0
Apache 2.2.11

Edited by mikef, 15 July 2009 - 03:02 PM.


#2 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 15 July 2009 - 03:06 PM

Wow...!!! Well, I just moved my WAMP server onto the bench to do some other testing so I'll make sure I have the newest release and see if I can get that error... Might be a while because that same machine is in the process of installing gOS on another drive...

#3 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 15 July 2009 - 03:56 PM

Looking at the changelog, E_DEPRECATED is new in 5.3

I've now added PHP 5.2.8 to my Wampserver config, and if I switch to that all is OK. (I've still got 5.3 installed, so can easily switch back if you want something tested.)

#4 Dean

    Loves Etomite Forums!

  • Admin
  • 4,746 posts
  • Gender:Male

Posted 15 July 2009 - 03:57 PM

View Postmikef, on 15 July 2009 - 03:56 PM, said:

Looking at the changelog, E_DEPRECATED is new in 5.3

Thanks for the heads-up Mike :)

#5 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 19 October 2009 - 09:35 AM

I installed the same environment and got the error Mike saw as well as an error saying something about not being able to pass values on an object by reference as it is depreciated as well. This was an error trying to access the manager (actually it made the manager totaly crash).

I had to get rid of the "&" from the manager/includes/browsercheck.inc.php at line 19:
$client =& new phpSniff($GET_VARS['UA'],$sniffer_settings);
now:
$client = new phpSniff($GET_VARS['UA'],$sniffer_settings);

and it works OK so far...

XAMPP for win 32 1.7.2
+ Apache 2.2.12 (IPV6 enabled)
+ MySQL 5.1.37 (Community Server) mit PBXT engine 1.0.08-rc
+ PHP 5.3.0 + PEAR (PEAR, Mail_Mime, MDB2, Zend)
+ Perl 5.10.0 (Bundle::Apache2, Bundle::Apache::ASP, Bundle::Email, Bundle::DBD::mysql, DBD::SQlite)
Etomite V1.1

#6 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 19 October 2009 - 09:57 AM

By the way, split() from above can successfully be substituted by explode() (index.php line approx 557) eto V1.1

$tempSnippetParams = explode($splitter, $tempSnippetParams);

I have not noticed and adverse side effects by doing this as yet and i had a few very delicate classes using snippet parameters extensively that were broken by split that are now OK.

#7 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 19 October 2009 - 10:46 AM

Looks like I don't have the abilit to edit posts anymore...

Anyway, after a run, I realised that the above will not work for & being passed in snippet params. It appears to be trying to get caught as alternative snippet parameter splitter:
$splitter = strpos($tempSnippetParams, "&")>0 ? "&" : "&";


Now this is where we were having problems passing a URL with a validating "&" in the snippet call. My vote is to stop looking for this as a parameter and just catch the & while ignoring the &

I don't know how many other people's code will get broken if this is done- so does anyone have a reason for passing & as a snippet parameter splitter?

If not, we could use:
 
 	$tempSnippetParams = str_replace("?", "", $currentSnippetParams);
 	//$splitter = strpos($tempSnippetParams, "&")> 0 ? "&" : "&";
		
 	$tempSnippetParams = explode("&", $tempSnippetParams);

Any ideas?

Now just in case I can't edit this post and & a m p ; gets resolved back to a single amperstand - there's quite a mix of amperstands and a m p s ; in the post above (in case it does not make sense).

#8 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 19 October 2009 - 12:49 PM

This is only related to PHP 5.3.x so far... I haven't heard of any related problems with PHP 5.2.x and doubt that there will be although PHP 5.2.x does have several quirks of its own...

#9 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 20 October 2009 - 08:15 AM

I think the need for taking & amp; as a splitter probably comes from the use of rich text editors for editting pages containing snippet calls with parameters. Any & entered is converted to & amp;

#10 Dean

    Loves Etomite Forums!

  • Admin
  • 4,746 posts
  • Gender:Male

Posted 20 October 2009 - 09:03 AM

View PostCris D., on 19 October 2009 - 10:46 AM, said:

Looks like I don't have the abilit to edit posts anymore...


This should be fixed.

#11 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 20 October 2009 - 11:14 AM

View PostDeanC, on 20 October 2009 - 09:03 AM, said:

This should be fixed.
- ta Dean.

Here's an "unofficial manager mod" but I've posted it here because it follows on...

//define characters to be passed (ignored)through snippet parameters	
$newParams = array("&&" , "??" ); 
$tempReplace=array("%amp%", "%quest%"); 
$oldParams = array("&", "?" );
	
for($i=0; $i<$nrSnippetsToGet; $i++) {
 	$parameter = array();
 	$snippetName = $this->currentSnippet = $snippets[$i]['name'];
 	$currentSnippetParams = $snippetParams[$i];

 	if(!empty($currentSnippetParams)) {
 	//replace & and ? in parameters to catch later
 	
 	//substitute flagged characters with a temporary placeholder
 	$tempSnippetParams = str_replace($newParams, $tempReplace, $currentSnippetParams);
 	
 	$tempSnippetParams = str_replace("?", "", $tempSnippetParams);
 	
 	$splitter = strpos($tempSnippetParams, "&amp;")> 0 ? "&amp;" : "&";
		$tempSnippetParams = explode($splitter, $tempSnippetParams);

 	for($x=0; $x<count($tempSnippetParams); $x++) {
 	$parameterTemp = explode("=", $tempSnippetParams[$x],2);
 	
 	//put required characters back in
 	$parameter[$parameterTemp[0]] = str_replace($tempReplace, $oldParams, $parameterTemp[1]);
 	}
 	}
 	$executedSnippets[$i] = $this->evalSnippet($snippets[$i]['snippet'], $parameter);

 	if($this->config['dumpSnippets']==1) {
 	echo "<fieldset><legend><b>$snippetName</b></legend><textarea style='width:60%; height:200px'>".htmlentities($executedSnippets[$i])."</textarea></fieldset>
";
 	}
 	$documentSource = str_replace("[[".$snippetName.$currentSnippetParams."]]", $executedSnippets[$i], $documentSource);
	}
	return $documentSource;
 } 

This section of the index.php will effectively let any & or ? character pass through the snippet parameters if you use it twice in a row (&& or ??). If you read the code above, it simply replaces flagged charaters with a temporary placeholder then when the snippet parameters are exploded, replaces them back with the required characters. Although only the & and ? characters are messed with in the existing code, this method will allow any html entitity to be passed- good for URLs and special characters.

To try use it, simply pass your parameters like this:

snippet?u=http://mysite.com/index.php??id=12&&amp;key1=value1&&amp;key2=value2&param2=value2

This will pass:
[u]=>[http://mysite.com/in...38;key2=value2]
(which will render XHTML compiant: http://mysite.com/in...mp;key2=value2)
[param2]=>[value2]

Edited by Cris D., 20 October 2009 - 11:21 AM.


#12 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 20 October 2009 - 02:17 PM

I'm trying to come up with an elegant regexp solution that can handle all cached and uncached snippet calls in a single call... That would be the most efficient method of handling this task when a document is being saved...

#13 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 20 October 2009 - 05:18 PM

Well, I didn't get a chance to track down a good regexp method but I did come up with the following code that seems to work adequately... We need to search for both cached and uncached snippet calls within the documents content field and clean up any &amp; tags so they are converted back into simple & characters... There is no html entity for the question mark character, at least not based on US-ASCII, so I didn't account for them here...

// find all cached and uncached snippet calls within the document content
preg_match_all('~\[+[\[\!](.*?)[\!\]]+\]~', $content, $matches);
// get a count of the matches array
$count = count($matches);
// if there are matches, process them
if($count)
{
 // loop through the array of matches
 for($i=0; $i<$count; $i++)
 {
 // make the second portion of the match the way we want it to be
 $matches[1][$i] = str_replace("&amp;", "&", $matches[0][$i]);
 // replace the original snippet call with the modified version
 $content = str_replace($matches[0][$i], $matches[1][$i], $content);
 }
 // clean up by getting rid of the matches
 unset($matches);
}

This code is intended to be placed in manager/processors/save_content_processor.php immediately below the variable assignment section, prior to inserting or updating...

This fix has been successfully tested using RTE, Xinha, TinyMCE, FCKEditor, as well as in non-Rich Text mode...

It should also be noted that this code only fixes the original problem, not the resulting problem caused by documents already saved with defective tags within snippet calls... I'll be playing with the code Cris D. posted to account for handling such instances...

#14 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 20 October 2009 - 08:41 PM

Ralph, I think we may be on 2 separate pages here...

I'm putting my business analyst hat on now and am going to state some "requirements" of this solution as I see it...

  • The soltuons must be able to pass &amp; and & through to the resulting rendered page if valid code is to be produced (particularly in URLs).
  • There needs to be scope where snippet calls are passed through other snippets using runSnippet() and don't ever appear in a content page.
  • There is a reqirement to be able to pass the & character as part of an html encoded character to create validating code through a snippet call without it used as a "splitter" to determine the key=>value snippet parameters.
  • There is a requirement to let "?" and possible "=" through as a snippe parameter (although there seems to be no issues with "=" at the moment).
  • There may be requirements to pass other characters due to various encoding sets and languages which can be configured.
The code above will remove &amp; from snippet calls and still let it act as a splitter - I don't know if this is actually required.

#15 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,506 posts
  • Gender:Male

Posted 20 October 2009 - 11:53 PM

Cris, take a closer look at the code I posted and where it goes... All my piece of code does is to clean up WYSIWYG rendered document content so that the parser doesn't gag on it as I have had happen several times over the years... It only looks at snippet calls and nothing else... If a document already resides in the database with a bad snippet call my piece of code won't be of help until that document is edited and re-saved...

I see a lot of room for improvement in the evalSnippets() function, as well as others, which is why I've been evaluating every aspect of how the parser functions... The overall size of the code can be reduced while adding functionality, and perhaps even more speed... Not to mention the elimination of deprecated function calls... One of my next tasks is to write some tight code for a truly recursive parser...

The entire code base is starting to show its age... Time... All I need is time... And money... And... And...:lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users