Jump to content
Fórum Script Brasil
  • 0

Erro de Syntax


silviofs

Question

Já tentei de tudo ao executar o programa aparece o seguinte:

syntax erro, unexpected ':', expecting ')'

o script e o seguinte:

$exception = new Exception(

       $throwable - > getMessage(),

       $throwable - > getCode(),

       $throwable

 );

Edited by silviofs
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Você não pode usar espaço entre a classe e o método: o correto é 

<?php
use PHPUnit\Framework\TestCase;

class ExceptionTest extends TestCase
{
    public function testCreateException()
    {
        $throwable = new Exception('Test exception', 123);
        $exception = new Exception(
            $throwable->getMessage(),
            $throwable->getCode(),
            $throwable
        );

        $this->assertEquals('Test exception', $exception->getMessage());
        $this->assertEquals(123, $exception->getCode());
        $this->assertSame($throwable, $exception->getPrevious());
    }
}

 

Link to comment
Share on other sites

  • 0

Você esqueceu de colocar o script completo. 

Aqui um exemplo de como você pode expor o problema:

Parse error: syntax error, unexpected token "?" in C:\wamp64\www\Astudy\index.php on line 28

File: index.php
01: <?php
02: class Teste
03: {
04:     function comecarDeNovo()
05:     {
06:         ?>
07:         <p>
08:         <form method=post action=index.php>
09:             <input type=submit value='Começar de novo'>
10:         </form>
11:         <?php
12:         exit;
13:     }
14:     function inicio()
15:     {
16:         ?>
17:         conteúdo do $_GET :
18:         <?=var_dump($_GET)?>
19:         conteúdo do $_POST :
20:         <?=var_dump($_POST)?>
21:         <?php 
22:         return $this->comecarDeNovo();   
23:     }
24: 
25:     function mensagem($problema)
26:     {
27:         
28:         Rota <?=json_encode($problema)?> inválida!
29:         <?php
30:         return $this->comecarDeNovo();
31:     }
32:     function naoFazerNada()
33:     {
34: 
35:     }
36: 
37: }
38: spl_autoload_register(fn ($class) => 
39: require str_replace('\\', DIRECTORY_SEPARATOR, strtolower($class)) . '.php');
40: $rota='Teste_naoFazerNada';
41: if($_GET)
42: {
43:     if(strpos(key($_GET),"_")==0)
44:     {
45:         return (new Teste)->mensagem($_GET);
46:     }
47:     $rota=isset($_GET) ? key($_GET) : $rota;
48: }
49: $segmentos=explode('_',$rota);
50: $nomeControle=$segmentos[0];
51: $metodo=$segmentos[1];
52: $parametro=$segmentos[2] ?? null;
53: $controle=new $nomeControle();
54: $controle->$metodo($parametro);
55: ?>
56: <form method=post action=?teste.inicio>
57:     <input type=submit name=bacalhau value=Teste>
58:     <input type=hidden name=sardinha value=nenhum>
59: </form>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...