PHP Array To String Notice

I get the following notice on my webpage.

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: libraries/Template.php
Line Number: 3859

The line number 3859 is this:
	 return str_replace(LD.$name.RD, $value, $string);

Open in new window


<div class="controls">
{select id="bike_type"}
{if option_first_row}<option value="">Select a Value</option>{/if}
<option {selected} value="{option_value}" >{option_name}</option>
{/select}
</div>

Open in new window

The Notice goes away if I remove value="{option_value}".  It does not like the curly brackets.  How can I change this so it is okay with the curly brackets?

The following is the entire Method.  It is part of the Expression Engine CMS.  Maybe it can be defined in here someplace?
	function _parse_var_single($name, $value, $string)
	{
		// parse date variables where applicable
		if (in_array($name, (array) $this->date_vars))
		{
			return $this->parse_date_variables($string, array($name => $value));
		}

		// Simple Variable - Find & Replace & Return
		if (is_string($value))
		{
			return str_replace(LD.$name.RD, $value, $string);
		}

		//
		// Complex Paths and Typography Variables
		//


		// If the single variable's value is an array, then
		// $value[0] is the content and $value[1] is an array
		// of parameters for the Typography class OR an indicator of a path variable
		if (is_array($value) && count($value) == 2 && is_array($value[1]))
		{
			$raw_content = $value[0];

			// Make our path switches
			if (isset($value[1]['path_variable']) && $value[1]['path_variable'] === TRUE)
			{
				if (preg_match_all("#".LD."\s*".$name."=(.*?)".RD."#", $string, $matches))
				{
					$done = array();

					foreach ($matches[0] as $full)
					{
						if (in_array($full, $done))
						{
							continue;
						}

						$link = ee()->functions->create_url(ee()->functions->extract_path($full).'/'.$value[0]);

					//$single_quote = str_replace("'", '"', $matches['0']);
					//$double_quote = str_replace("'", '"', $matches['0']);

	//[0] => {id_path="about/test"}
	//[1] => "about/test"

					// Switch to double quotes

						$single = str_replace(array('"', "'"), "'", $full);
						$double = str_replace(array('"', "'"), '"', $full);

					//echo $single.' - '.$double.'<br>';
						$string = str_replace($single, $double, $string);
					//echo $string;
					//echo '<br>-----------------------<br>';

						$string = str_replace($double, $link, $string);

						$done[] = $full;

					}
				}

				return $string;
			}


			$prefs = array();

			foreach (array('text_format', 'html_format', 'auto_links', 'allow_img_url', 'convert_curly') as $pref)
			{
				if (isset($value[1][$pref]))
				{
					$prefs[$pref] = $value[1][$pref];
				}
			}

			// Instantiate Typography only if necessary
			ee()->load->library('typography');
			ee()->typography->initialize(array(
				'convert_curly'	=> (isset($prefs['convert_curly']) && $prefs['convert_curly'] == 'n') ? FALSE : TRUE)
				);

			$value = ee()->typography->parse_type($raw_content, $prefs);


		}

		if (isset($raw_content))
		{
			$this->conditional_vars[$name] = $raw_content;
		}
		//  SPOKE Modification.  I commented out the return.  It was causing a PHP Notice.  It is because it does not like any info inside of an option.
		 return str_replace(LD.$name.RD, $value, $string);

	}

Open in new window

LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
That error typically occurs when you try to access an array as a string.  Even when all the array elements are strings, you have to pass them individually in the format $array[0] or $array['name'].  (Substitute the name of your array in place of 'array')  You can't pass the whole array.
rgranlundAuthor Commented:
I'm not sure I understand that as it applies to what I have posted.  Can you elaborate just a little more?
Dave BaldwinFixer of ProblemsCommented:
If any of the variable values in line 3859 above is an array instead of a simple string, the function call will fail with the error you mentioned at the top.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Marco GasiFreelancerCommented:
Hi rgranlund. Let me say I never used and I don't know expression-engine. That said, looking at your function I see there are 2 main conditions:

if (is_string($value)) {

Open in new window


and

if (is_array($value) && count($value) == 2 && is_array($value[1])) {

Open in new window


Depending of the value of this conditions the value of the variable $value is set. Now, is it possible that the second condition is only partially true? That is: could be $value an array but its count be 1 or 3 or other or be its first value not an array? Because if $value is an array the first condition is false but if it is an array but its count is let's say 4 or its first element is not an array the second condition too ius false and so at the end of the function when you have:

return str_replace(LD . $name . RD, $value, $string);

Open in new window


$value is still an array and this raises the Notice. I think this is the problem and you have to investigate about this. Maybe you can elaborate the condition and set $value as string even if the other two conditions are false

if (is_array($value){
  if ( count($value) == 2 && is_array($value[1]){
     ...
  }
  else
  {
     ... make somehow $value be a string
   }
}

Open in new window

rgranlundAuthor Commented:
After reading and re-reading the comments and suggestions, I realized that with Expression Engine at times you need to use tag pairs to take care of the Curly Bracket issue.  Thanks for getting me on the correct path.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.