Foros del Web » Programando para Internet » PHP »

Error unexpected ';', expecting T_FUNCTION

Estas en el tema de Error unexpected ';', expecting T_FUNCTION en el foro de PHP en Foros del Web. me sale ese error usando un script que necesito . version php 5.2.15 Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/psnotic1/public_html/media/includes/form.php on line ...
  #1 (permalink)  
Antiguo 12/01/2011, 20:30
 
Fecha de Ingreso: enero-2011
Mensajes: 2
Antigüedad: 13 años, 3 meses
Puntos: 0
Exclamación Error unexpected ';', expecting T_FUNCTION

me sale ese error usando un script que necesito .
version php 5.2.15

Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/psnotic1/public_html/media/includes/form.php on line 1


Código PHP:
<? 

class Form
{
   var 
$values = array();  //Holds submitted form field values
   
var $errors = array();  //Holds submitted form error messages
   
var $num_errors;   //The number of errors in submitted form

   /* Class constructor */

   
function Form(){

      
/**
       * Get form value and error arrays, used when there
       * is an error with a user-submitted form.
       */

      
if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){
         
$this->values $_SESSION['value_array'];
         
$this->errors $_SESSION['error_array'];
         
$this->num_errors count($this->errors);

         unset(
$_SESSION['value_array']);
         unset(
$_SESSION['error_array']);
      }

      else{

         
$this->num_errors 0;

      }
   }


   
/**
    * setValue - Records the value typed into the given
    * form field by the user.
    */

   
function setValue($field$value){
      
$this->values[$field] = $value;
   }

   
/**
    * setError - Records new form error given the form
    * field name and the error message attached to it.
    */

   
function setError($field$errmsg){
      
$this->errors[$field] = $errmsg;
      
$this->num_errors count($this->errors);
   }

   
/**
    * value - Returns the value attached to the given
    * field, if none exists, the empty string is returned.
    */

   
function value($field){
      if(
array_key_exists($field,$this->values)){
         return 
htmlspecialchars(stripslashes($this->values[$field]));
      }else{
         return 
"";
      }
   }


   
/**
    * error - Returns the error message attached to the
    * given field, if none exists, the empty string is returned.
    */

   
function error($field){
      if(
array_key_exists($field,$this->errors)){
         return 
"<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
      }else{
         return 
"";
      }
   }

   
/* getErrorArray - Returns the array of error messages */

   
function getErrorArray(){
      return 
$this->errors;
   }
};


?>
sabrian decirme si hay algo mal?
  #2 (permalink)  
Antiguo 12/01/2011, 20:36
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Error unexpected ';', expecting T_FUNCTION

me pregunto que pasaría si usas <?php como debe de ser...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 12/01/2011, 20:36
 
Fecha de Ingreso: enero-2011
Mensajes: 13
Antigüedad: 13 años, 3 meses
Puntos: 1
Respuesta: Error unexpected ';', expecting T_FUNCTION

No se mucho sobre el tema, pero creo que php 5.x no permite empezar con <? Hay que empezar con <?php

Fijate eso.
  #4 (permalink)  
Antiguo 12/01/2011, 23:12
 
Fecha de Ingreso: enero-2011
Mensajes: 5
Antigüedad: 13 años, 3 meses
Puntos: 1
Respuesta: Error unexpected ';', expecting T_FUNCTION

Cita:
Iniciado por pateketrueke Ver Mensaje
me pregunto que pasaría si usas <?php como debe de ser...
exacto es la manera correcta de escribirlo, ya que la sintaxis que usas no es soportada por ejemplo en todos los hostings
  #5 (permalink)  
Antiguo 13/01/2011, 05:57
 
Fecha de Ingreso: enero-2011
Mensajes: 2
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Error unexpected ';', expecting T_FUNCTION

Cita:
Iniciado por pateketrueke Ver Mensaje
me pregunto que pasaría si usas <?php como debe de ser...
Grracias por las respuestas, pero pongo <?php y sigo teniendo el mismo problema.

Cita:
Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/psnotic1/public_html/media/includes/form.php on line 1
Código PHP:
<?php 

class Form
{
   var 
$values = array();  //Holds submitted form field values
   
var $errors = array();  //Holds submitted form error messages
   
var $num_errors;   //The number of errors in submitted form

   /* Class constructor */

   
function Form(){

      
/**
       * Get form value and error arrays, used when there
       * is an error with a user-submitted form.
       */

      
if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){
         
$this->values $_SESSION['value_array'];
         
$this->errors $_SESSION['error_array'];
         
$this->num_errors count($this->errors);

         unset(
$_SESSION['value_array']);
         unset(
$_SESSION['error_array']);
      }

      else{

         
$this->num_errors 0;

      }
   }


   
/**
    * setValue - Records the value typed into the given
    * form field by the user.
    */

   
function setValue($field$value){
      
$this->values[$field] = $value;
   }

   
/**
    * setError - Records new form error given the form
    * field name and the error message attached to it.
    */

   
function setError($field$errmsg){
      
$this->errors[$field] = $errmsg;
      
$this->num_errors count($this->errors);
   }

   
/**
    * value - Returns the value attached to the given
    * field, if none exists, the empty string is returned.
    */

   
function value($field){
      if(
array_key_exists($field,$this->values)){
         return 
htmlspecialchars(stripslashes($this->values[$field]));
      }else{
         return 
"";
      }
   }


   
/**
    * error - Returns the error message attached to the
    * given field, if none exists, the empty string is returned.
    */

   
function error($field){
      if(
array_key_exists($field,$this->errors)){
         return 
"<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
      }else{
         return 
"";
      }
   }

   
/* getErrorArray - Returns the array of error messages */

   
function getErrorArray(){
      return 
$this->errors;
   }
};


?>
  #6 (permalink)  
Antiguo 13/01/2011, 12:25
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Error unexpected ';', expecting T_FUNCTION

Creo tu problema es el último ; que tienes al final de la declaración de tu clase.
  #7 (permalink)  
Antiguo 13/01/2011, 13:45
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Error unexpected ';', expecting T_FUNCTION

Cita:
Iniciado por GatorV Ver Mensaje
Creo tu problema es el último ; que tienes al final de la declaración de tu clase.
y ni eso es... lo curioso es que copie y pegue dicho código en un script, y lo ejecutó sin problemas!! (yo uso php 5.3)

pienso que nos esta mostrando un código que no es, sinceramente ignoro...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #8 (permalink)  
Antiguo 13/01/2011, 15:58
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Error unexpected ';', expecting T_FUNCTION

Cita:
Iniciado por pateketrueke Ver Mensaje
y ni eso es... lo curioso es que copie y pegue dicho código en un script, y lo ejecutó sin problemas!! (yo uso php 5.3)

pienso que nos esta mostrando un código que no es, sinceramente ignoro...
puede ser, ya que igual corre bien ese código...

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:58.