kepala
Goto Top

Parse error: syntax error, unexpected else (T ELSE), expecting function (T FUNCTION)

Hallo,

ich habe oben genannte Fehler, komme aber in PHP nicht sooo gut zurecht. Es waren noch einige andere Fehler drin, welche ich aber schon reparieren konnte. Ich habe mit PHPDesigner 8 mir betreffende Datei angeschau und bekomme diesen Code

<?php
/**
 * @version		$Id: select.php 20640 2011-02-10 06:26:40Z infograf768 $
 * @package		Joomla.Framework
 * @subpackage	HTML
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

/**
 * Utility class for creating HTML select lists
 *
 * @static
 * @package		Joomla.Framework
 * @subpackage	HTML
 * @since		1.5
 */
abstract class JHtmlSelect
{
	/**
	 * Default values for options. Organized by option group.
	 *
	 * @var array
	 */
	static protected $_optionDefaults = array(
		'option' => array(  
			'option.attr' => null,  
			'option.disable' => 'disable',  
			'option.id' => null,  
			'option.key' => 'value',  
			'option.key.toHtml' => true,  
			'option.label' => null,  
			'option.label.toHtml' => true,  
			'option.text' => 'text',  
			'option.text.toHtml' => true,  
		),
	);

	/**
	* Generates a yes/no radio list.
	*
	* @param string The value of the HTML name attribute
	* @param string Additional HTML attributes for the <select> tag
	* @param mixed The key that is selected
	* @return string HTML for the radio list
	*/
	public static function booleanlist(
		$name, $attribs = null, $selected = null, $yes = 'JYES', $no = 'JNO', $id = false  
	) {
		$arr = array(
			JHtml::_('select.option', '0', JText::_($no)),  
			JHtml::_('select.option', '1', JText::_($yes))  
		);
		return JHtml::_('serray_merge($options, $optKey)')  
		} else {
			// Get options from the parameters
			$options['option.key'] = $optKey;  
			$options['option.text'] = $optText;  
			$options['disable'] = $disable;  
		}
		$obj = new JObject;
		$obj->$options['option.key'] = $value;  
		$obj->$options['option.text'] = trim($text) ? $text : $value;  

		/*
		 * If a label is provided, save it. If no label is provided and there is
		 * a label name, initialise to an empty string.
		 */
		$hasProperty = $options['option.label'] !== null;  
		if (isset($options['label'])) {  
			$labelProperty = $hasProperty ? $options['option.label'] : 'label';  
			$obj->$labelProperty = $options['label'];  
		} elseif ($hasProperty) {
			$obj->$options['option.label'] = '';  
		}

		// Set attributes only if there is a property and a value
		if ($options['attr'] !== null) {  
			$obj->$options['option.attr'] = $options['attr'];  
		}

		// Set disable only if it has a property and a value
		if ($options['disable'] !== null) {  
			$obj->$options['option.disable'] = $options['disable'];  
		}
		return $obj;
	}

	/**
	 * Generates the option tags for an HTML select list (with no select tag
	 * surrounding the options).
	 *
	 * @param	array	An array of objects, arrays, or values.
	 * @param	mixed	If a string, this is the name of the object variable for
	 * the option value. If null, the index of the array of objects is used. If
	 * an array, this is a set of options, as key/value pairs. Valid options
	 * are:
	 * <ul><li>Format options, {@see JHtml::$formatOptions}.
	 * </li><li>groups: Boolean. If set, looks for keys with the value
	 * "&lt;optgroup>" and synthesizes groups from them. Deprecated. Defaults 
	 * true for backwards compatibility.
	 * </li><li>list.select: either the value of one selected option or an array
	 * of selected options. Default: none.
	 * </li><li>list.translate: Boolean. If set, text and labels are translated via
	 * JText::_(). Default is false.
	 * </li><li>option.id: The property in each option array to use as the
	 * selection id attribute. Defaults to none.
	 * </li><li>option.key: The property in each option array to use as the
	 * selection value. Defaults to "value". If set to null, the index of the 
	 * option array is used.
	 * </li><li>option.label: The property in each option array to use as the
	 * selection label attribute. Defaults to null (none).
	 * </li><li>option.text: The property in each option array to use as the
	 * displayed text. Defaults to "text". If set to null, the option array is 
	 * assumed to be a list of displayable scalars.
	 * </li><li>option.attr: The property in each option array to use for
	 * additional selection attributes. Defaults to none.
	 * </li><li>option.disable: The property that will hold the disabled state.
	 * Defaults to "disable". 
	 * </li><li>option.key: The property that will hold the selection value.
	 * Defaults to "value". 
	 * </li><li>option.text: The property that will hold the the displayed text.
	 * Defaults to "text". If set to null, the option array is assumed to be a 
	 * list of displayable scalars.
	 * </li></ul>
	 * @param	string  The name of the object variable for the option text.
	 * @param	mixed	The key that is selected (accepts an array or a string)
	 * @return  string  HTML for the select list
	 */
	public static function options(
		$arr, $optKey = 'value', $optText = 'text', $selected = null, $translate = false  
	) {
		$options = array_merge(
			JHtml::$formatOptions,
			self::$_optionDefaults['option'],  
			array(
				'format.depth' => 0,  
				'groups' => true,  
				'list.select' => null,  
				'list.translate' => false,  
			)
		);
		if (is_array($optKey)) {
			// Set default options and overwrite with anything passed in
			$options = array_merge($options, $optKey);
		} else {
			// Get options from the parameters
			$options['option.key'] = $optKey;  
			$options['option.text'] = $optText;  
			$options['list.select'] = $selected;  
			$options['list.translate'] = $translate;  
		}

		$html = '';  
		$baseIndent = str_repeat($options['format.indent'], $options['format.depth']);  

		foreach ($arr as $elementKey => &$element)
		{
			$attr = '';  
			$extra = '';  
			$label = '';  
			$id = '';  
			if (is_array($element))
			{
				$key = $options['option.key'] === null  
					? $elementKey : $element[$options['option.key']];  
				$text = $element[$options['option.text']];  
				if (isset($element[$options['option.attr']])) {  
					$attr = $element[$options['option.attr']];  
				}
				if (isset($element[$options['option.id']])) {  
					$id = $element[$options['option.id']];  
				}
				if (isset($element[$options['option.label']])) {  
					$label = $element[$options['option.label']];  
				}
				if (isset($element[$options['option.disable']]) && $element[$options['option.disable']]) {  
					$extra .= ' disabled="disabled"';  
				}
			} elseif (is_object($element)) {
				$key = $options['option.key'] === null  
					? $elementKey : $element->$options['option.key'];  
				$text = $element->$options['option.text'];  
				if (isset($element->$options['option.attr'])) {  
					$attr = $element->$options['option.attr'];  
				}
				if (isset($element->$options['option.id'])) {  
					$id = $element->$options['option.id'];  
				}
				if (isset($element->$options['option.label'])) {  
					$label = $element->$options['option.label'];  
				}
				if (isset($element->$options['option.disable']) && $element->$options['option.disable']) {  
					$extra .= ' disabled="disabled"';  
				}
			} else {
				// This is a simple associative array
				$key = $elementKey;
				$text = $element;
			}

			/*
			 * The use of options that contain optgroup HTML elements was
			 * somewhat hacked for J1.5. J1.6 introduces the grouplist() method
			 * to handle this better. The old solution is retained through the
			 * "groups" option, which defaults true in J1.6, but should be 
			 * deprecated at some point in the future.
			 */
			$key = (string) $key;
			if ($options['groups'] && $key == '<OPTGROUP>') {  
				$html .= $baseIndent . '<optgroup label="'  
					. ($options['list.translate'] ? JText::_($text) : $text)  
					. '">' . $options['format.eol'];  
				$baseIndent = str_repeat($options['format.indent'], ++$options['format.depth']);  
			} else if ($options['groups'] && $key == '</OPTGROUP>') {  
				$baseIndent = str_repeat($options['format.indent'], --$options['format.depth']);  
				$html .= $baseIndent . '</optgroup>' . $options['format.eol'];  
			} else {
				// if no string after hypen - take hypen out
				$splitText = explode(' - ', $text, 2);  
				$text = $splitText;
				if (isset($splitText[1])) {
					$text .= ' - ' . $splitText[1];  
				}

				if ($options['list.translate'] && !empty($label)) {  
					$label = JText::_($label);
				}
				if ($options['option.label.toHtml']) {  
					$label = htmlentities($label);
				}
				if (is_array($attr)) {
					$attr = JArrayHelper::toString($attr);
				} else {
					$attr = trim($attr);
				}
				$extra = ($id ? ' id="' . $id . '"' : '')  
					. ($label ? ' label="' . $label . '"' : '')  
					. ($attr ? ' ' . $attr : '')  
					. $extra
				;
				if (is_array($options['list.select']))  
				{
					foreach ($options['list.select'] as $val)  
					{
						$key2 = is_object($val) ? $val->$options['option.key'] : $val;  
						if ($key == $key2) {
							$extra .= ' selected="selected"';  
							break;
						}
					}
				} elseif ((string)$key == (string)$options['list.select']) {  
					$extra .= ' selected="selected"';  
				}

				if ($options['list.translate']) {  
					$text = JText::_($text);
				}

				// Generate the option, encoding as required
				$html .= $baseIndent . '<option value="'  
					. ($options['option.key.toHtml'] ? htmlspecialchars($key, ENT_COMPAT, 'UTF-8') : $key) . '"'  
					. $extra . '>'  
					. ($options['option.text.toHtml'] ? htmlentities(html_entity_decode($text), ENT_COMPAT, 'UTF-8') : $text)  
					. '</option>'  
					. $options['format.eol']  
				;
			}
		}

		return $html;
	}

	/**
	* Generates an HTML radio list.
	*
	* @param array An array of objects
	* @param string The value of the HTML name attribute
	* @param string Additional HTML attributes for the <select> tag
	* @param mixed The key that is selected
	* @param string The name of the object variable for the option value
	* @param string The name of the object variable for the option text
	* @return string HTML for the select list
	*/
	public static function radiolist(
		$data, $name, $attribs = null, $optKey = 'value', $optText = 'text',  
		$selected = null, $idtag = false, $translate = false
	) {
		reset($data);
		$html = '';  

		if (is_array($attribs)) {
			$attribs = JArrayHelper::toString($attribs);
		}

		$id_text = $idtag ? $idtag : $name;

		foreach ($data as $ind => $obj)
		{
			$k  = $obj->$optKey;
			$t  = $translate ? JText::_($obj->$optText) : $obj->$optText;
			$id = (isset($obj->id) ? $obj->id : null);

			$extra  = '';  
			$extra  .= $id ? ' id="' . $obj->id . '"' : '';  
			if (is_array($selected))
			{
				foreach ($selected as $val)
				{
					$k2 = is_object($val) ? $val->$optKey : $val;
					if ($k == $k2)
					{
						$extra .= ' selected="selected"';  
						break;
					}
				}
			} else {
				$extra .= ((string)$k == (string)$selected ? ' checked="checked"' : '');  
			}
			$html .= "\n\t" .'<input type="radio" name="' . $name . '"'  
				. ' id="' . $id_text . $k . '" value="' . $k .'"'  
				. ' ' . $extra . ' ' . $attribs . '/>'  
				. "\n\t" . '<label for="' . $id_text . $k . '"'  
				. ' id="' . $id_text . $k . '-lbl" class="radiobtn">'.$t.'</label>';  
		}
		$html .= "\n";  
		return $html;
	}

}

Betreffende Zeile ist hierbei die Zeile 55 mit dem Wort else. Ich komme nicht damit klar was hier noch falsch sein sollte. Kann mir dabei bitte jemand helfen?

LG Kepala

Content-Key: 220876

Url: https://administrator.de/contentid/220876

Printed on: April 20, 2024 at 02:04 o'clock

Member: colinardo
colinardo Oct 31, 2013 updated at 10:25:01 (UTC)
Goto Top
Hallo Kepala,
ist ja klar, da fehlt der if (Bedingung) { Teil vor Zeile 55 und in Zeile 54 das abschließende Semikolon.
Was aber die Bedingung sein soll kann ich aus dem Code in der Schnelle nicht erschließen ...

Grüße Uwe
Member: Kepala
Kepala Oct 31, 2013 at 10:25:28 (UTC)
Goto Top
Und wie soll die Zeile dann aussehen?
Member: Bitboy
Bitboy Oct 31, 2013 at 10:29:25 (UTC)
Goto Top
Hi,

ohne jetzt besonderer PHP Kenner zu sein würde ich sagen in Zeile 49 beginnt die Funktion und vor dem Else wird die mit der } schon wieder zugemacht.
Abgesehen davon fehlt dem Else auch ein If

Um das zu lösen müsste wohl zwischen Zeile 49 und 50 etwas wie If (irgendwas) { eingefügt werden.
Member: colinardo
colinardo Oct 31, 2013 at 10:29:45 (UTC)
Goto Top
Zitat von @Kepala:
Und wie soll die Zeile dann aussehen?
Ich hab das Ding nicht geschrieben ! woher soll ich dann wissen welche Bedingung drin stehen soll:
Die hast du wahrscheinlich irgendwie rausgelöscht...hol dir die Original-Datei aus den Joomla-Repos fertig ....
if (BEDINGUNG DIE ICH NICHT KENNE){
      //MACH hier was 
} else {
	// Get options from the parameters
	$options['option.key'] = $optKey;  
	$options['option.text'] = $optText;  
	$options['disable'] = $disable;  
}

Grüße Uwe
Member: Kepala
Kepala Oct 31, 2013 at 10:33:51 (UTC)
Goto Top
Das seltsame ist dass ich den Code so aus meiner Sicherung habe, die ich direkt gemacht habe bevor ich was an der Seite verändern wollte. Dann ging die Seite nicht mehr und ich habe alles neu hochgeladen und danach gings auf einmal nicht mehr.
Member: Kepala
Kepala Oct 31, 2013 at 10:42:26 (UTC)
Goto Top
So ich danke Euch liebe Leute... Habs mit Eurer Hilfe lösen können... Juhuu... Ich hab soooo weit um die ecke gedacht, dass ich nicht drauf gekommen bin mir die richtige Joomla Version nochmal runterzuladen und nur die betreffende Datei neu einzuspielen... Es scheint wieder alles zu funktionieren...
Member: colinardo
colinardo Oct 31, 2013 at 11:07:55 (UTC)
Goto Top
Dann bitte noch den Beitrag auf gelöst setzen. Merci.