Ir para conteúdo
Fórum Script Brasil
  • 0

PHP Erros PHP no site tipo autoload() depois que o hostgator att seu servidor!


ssj4bq

Pergunta

Olá senhores,

Meu site funcionava perfeitamente no servidor da hostgator mais eles atualizaram o servidor para se não me engano PHP 7.4 e ai mudaram sintaxes o site não queria mais abrir fui fazendo umas modificações mas ainda a erros.

Exemplos de modificação.

Porém corrigindo erro ali e erro aqui, o site ainda não logo mais como se não tivesse usuário, mas tem cadastrado nem aparece as categorias em PHP, e tem esse erro no rodapé anexo 3:

function __autoload($class_name) {

Em que substitui por o comando spl_autoload_registerfunction ($class_name) {

Segue codigo:

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

Porem da erro na linha 46 em negrito function import($funcpre) { segue abaixo o erro:

Array
(
    [type] => 4
    [message] => syntax error, unexpected 'public' (T_PUBLIC), expecting ')'
    [file] => /home2/tesour07/public_html/include/application.php
    [line] => 46
)

A questão é como corrigir esse erro:

/* important function */
spl_autoload_register(function ($class_name) {



Ai deu erro na linha 46 que é essa:



function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

 

Esta falando de tirar alguma coisa de hide e reescrever a função, so que naõ entendo como seria, na linha 46

 

Array

       ( [type] => 4

        [message] => syntax error, unexpected 'public' (T_PUBLIC), expecting ')'

        [file] => /home2/tesour07/public_html/include/application.php

        [line] => 46 )



function import($funcpre) {

 

Obrigado a todos

2022-07-20_212228.png

2022-07-20_212220.png

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

Eu só sei 2% de PHP, mas já aprendi com ele sobre esses erros enigmáticos. Quando o PHP reclama que tem problema na linha 30, eu logo vou procurar o erro na linha anterior.

O meu problema é que você listou da linha 46 e 51.

Assim eu improvisei assim:

function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

e assim o PHP parou de reclamar da função que apontou, mas ele aponta um novo erro.

spl_autoload_register(function ($class_name) 

Eu pesquisei PHP: spl_autoload_register - Manual, mas não encontrei nada parecido com essa sintaxe. Para mim, a sintaxe que eu esperava é algo do tipo spl_autoload_register($class_name), mas sem nenhuma instução adiante.

e

Editado por Frank K Hosaka
Link para o comentário
Compartilhar em outros sites

  • 0
11 horas atrás, Frank K Hosaka disse:

Eu só sei 2% de PHP, mas já aprendi com ele sobre esses erros enigmáticos. Quando o PHP reclama que tem problema na linha 30, eu logo vou procurar o erro na linha anterior.

O meu problema é que você listou da linha 46 e 51.

Assim eu improvisei assim:

function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

e assim o PHP parou de reclamar da função que apontou, mas ele aponta um novo erro.

spl_autoload_register(function ($class_name) 

Eu pesquisei PHP: spl_autoload_register - Manual, mas não encontrei nada parecido com essa sintaxe. Para mim, a sintaxe que eu esperava é algo do tipo spl_autoload_register($class_name), mas sem nenhuma instução adiante.

e

Certo eu fiz igual você postou e mudou o erro, vou postar o código limpo já que você disse que não tem ele no inicio, isso era ele quando funcionava no PHP anterior:
 

<?php
/* for rewrite or iis rewrite */
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
} else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
/* end */

error_reporting(E_ALL^E_WARNING^E_NOTICE);
define('SYS_VERSION', '3.0 BR_PT');
define('SYS_SUBVERSION', '06-01-2011');
define('SYS_TIMESTART', microtime(true));
define('SYS_REQUEST', isset($_SERVER['REQUEST_URI']));
define('DIR_SEPERATOR', strstr(strtoupper(PHP_OS), 'WIN')?'\\':'/');
define('DIR_ROOT', str_replace('\\','/',dirname(__FILE__)));
define('DIR_LIBARAY', DIR_ROOT . '/library');
define('DIR_CLASSES', DIR_ROOT . '/classes');
define('DIR_COMPILED', DIR_ROOT . '/compiled');
define('DIR_TEMPLATE', DIR_ROOT . '/template');
define('DIR_FUNCTION', DIR_ROOT . '/function');
define('DIR_CONFIGURE', DIR_ROOT . '/configure');
define('SYS_MAGICGPC', get_magic_quotes_gpc());
define('SYS_PHPFILE', DIR_ROOT . '/configure/system.php');
define('WWW_ROOT', rtrim(dirname(DIR_ROOT),'/'));
define('IMG_ROOT', dirname(DIR_ROOT) . '/static');

/* encoding */
mb_internal_encoding('UTF-8');
/* end */

/* important function */
function __autoload($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

/* json */
if (!function_exists('json_encode')){function json_encode($v){$js = new JsonService(); return $js->encode($v);}}
if (!function_exists('json_decode')){function json_decode($v,$t){$js = new JsonService($t?16:0); return $js->decode($v);}}
/* end json */

/* date_zone */
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Brazil/East'); }
/* end date_zone */

/* import */
import('template');
import('common');

/* ob_handler */
if(SYS_REQUEST){ ob_get_clean(); ob_start(); }
/* end ob */

Ai eu fiz a modificação function __autoload($class_name) { para spl_autoload_register pois tinha erro na sintaxe, ficando assim:

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

Porem da erro na linha 46 em negrito function import($funcpre) { esse erro:

Array

       ( [type] => 4

        [message] => syntax error, unexpected 'public' (T_PUBLIC), expecting ')'

        [file] => /home2/tesour07/public_html/include/application.php

        [line] => 46 )

Testei seu código improvisado:

/* important function */
function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

Ai deu agora esse erro em anexo:

Array
(
    [type] => 4
    [message] => syntax error, unexpected 'if' (T_IF), expecting ')'
    [file] => /home2/tesour07/public_html/include/application.php
    [line] => 54
)

Deixei o código original abaixo, para ver caso queira sem nenhuma modificação e que funcionava antes nos PHP anteriores.

<?php
/* for rewrite or iis rewrite */
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
	$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
} else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
	$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
/* end */

error_reporting(E_ALL^E_WARNING^E_NOTICE);
define('SYS_VERSION', '3.0 BR_PT');
define('SYS_SUBVERSION', '06-01-2011');
define('SYS_TIMESTART', microtime(true));
define('SYS_REQUEST', isset($_SERVER['REQUEST_URI']));
define('DIR_SEPERATOR', strstr(strtoupper(PHP_OS), 'WIN')?'\\':'/');
define('DIR_ROOT', str_replace('\\','/',dirname(__FILE__)));
define('DIR_LIBARAY', DIR_ROOT . '/library');
define('DIR_CLASSES', DIR_ROOT . '/classes');
define('DIR_COMPILED', DIR_ROOT . '/compiled');
define('DIR_TEMPLATE', DIR_ROOT . '/template');
define('DIR_FUNCTION', DIR_ROOT . '/function');
define('DIR_CONFIGURE', DIR_ROOT . '/configure');
define('SYS_MAGICGPC', get_magic_quotes_gpc());
define('SYS_PHPFILE', DIR_ROOT . '/configure/system.php');
define('WWW_ROOT', rtrim(dirname(DIR_ROOT),'/'));
define('IMG_ROOT', dirname(DIR_ROOT) . '/static');

/* encoding */
mb_internal_encoding('UTF-8');
/* end */

/* important function */
function __autoload($class_name) {
	$file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
	$file_path = DIR_LIBARAY. '/' . $file_name;
	if ( file_exists( $file_path ) ) {
		return require_once( $file_path );
	}
	$file_path = DIR_CLASSES. '/' . $file_name;
	if ( file_exists( $file_path ) ) {
		return require_once( $file_path );
	}
	return false;
}

function import($funcpre) {
	$file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
	if (file_exists($file_path) ) {
		require_once( $file_path );
	}
}

/* json */
if (!function_exists('json_encode')){function json_encode($v){$js = new JsonService(); return $js->encode($v);}}
if (!function_exists('json_decode')){function json_decode($v,$t){$js = new JsonService($t?16:0); return $js->decode($v);}}
/* end json */

/* date_zone */
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Brazil/East'); }
/* end date_zone */

/* import */
import('template');
import('common');

/* ob_handler */
if(SYS_REQUEST){ ob_get_clean(); ob_start(); }
/* end ob */

E o modificado agora com erro em anexo:

<?php
/* for rewrite or iis rewrite */
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
} else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
/* end */

error_reporting(E_ALL^E_WARNING^E_NOTICE);
define('SYS_VERSION', '3.0 BR_PT');
define('SYS_SUBVERSION', '06-01-2011');
define('SYS_TIMESTART', microtime(true));
define('SYS_REQUEST', isset($_SERVER['REQUEST_URI']));
define('DIR_SEPERATOR', strstr(strtoupper(PHP_OS), 'WIN')?'\\':'/');
define('DIR_ROOT', str_replace('\\','/',dirname(__FILE__)));
define('DIR_LIBARAY', DIR_ROOT . '/library');
define('DIR_CLASSES', DIR_ROOT . '/classes');
define('DIR_COMPILED', DIR_ROOT . '/compiled');
define('DIR_TEMPLATE', DIR_ROOT . '/template');
define('DIR_FUNCTION', DIR_ROOT . '/function');
define('DIR_CONFIGURE', DIR_ROOT . '/configure');
define('SYS_MAGICGPC', get_magic_quotes_gpc());
define('SYS_PHPFILE', DIR_ROOT . '/configure/system.php');
define('WWW_ROOT', rtrim(dirname(DIR_ROOT),'/'));
define('IMG_ROOT', dirname(DIR_ROOT) . '/static');

/* encoding */
mb_internal_encoding('UTF-8');
/* end */

/* important function */
function import($funcpre) {
    $file_path = DIR_FUNCTION. '/' . $funcpre . '.php';
    if (file_exists($file_path) ) {
        require_once( $file_path );
    }
}

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

/* json */
if (!function_exists('json_encode')){function json_encode($v){$js = new JsonService(); return $js->encode($v);}}
if (!function_exists('json_decode')){function json_decode($v,$t){$js = new JsonService($t?16:0); return $js->decode($v);}}
/* end json */

/* date_zone */
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Brazil/East'); }
/* end date_zone */

/* import */
import('template');
import('common');

/* ob_handler */
if(SYS_REQUEST){ ob_get_clean(); ob_start(); }
/* end ob */

2022-07-21_191421.png

Editado por ssj4bq
Link para o comentário
Compartilhar em outros sites

  • 0

Eu bato na mesma tecla, o problema é sempre a linha anterior e não o que o PHP aponta

O seu código é esse:

spl_autoload_register(function ($class_name) {
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {
        return require_once( $file_path );
    }
    return false;
}

eu fiz um monte de teste e cheguei nesse código:

spl_autoload_register(function ($class_name){
    $file_name = trim(str_replace('_','/',$class_name),'/').'.class.php';
    $file_path = DIR_LIBARAY. '/' . $file_name;
    if ( file_exists( $file_path ) ) {return require_once( $file_path );}
    $file_path = DIR_CLASSES. '/' . $file_name;
    if ( file_exists( $file_path ) ) {return require_once( $file_path );}
    return false;
});

comparando com o seu código, tudo indica que falta um parentesis e um ponto e vírgula.

Mas aí surgiu um problema no código:
define('SYS_MAGICGPC', get_magic_quotes_gpc());

O maior problema é que eu só tenho 2% de PHP, eu não tenho a menor ideia do que esses códigos fazem.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...