My PHP tags do not work

0

I'm programming in PHP a function to connect to the mysql DB, but I think the system is not recognizing the php lines. Because I've tried even with a simple "helloMundo.php" and does not recognize it. Specify that I have the tags activated, I attach a capture of the code that I am working on.

I get this error when sending to the browser.  Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C: \ wamp \ www \ Web System \ online.php 23 Call Stack

The line it refers to is: public function execute ()

    
asked by Steven Andrade 28.04.2018 в 17:18
source

1 answer

2

You have a function within the constructor of the class declared as public and that is not possible since everything within a function is private:

class Conexion
{
   public function __construct()
   {
      // error aqui, ejecutar siempre sera privado
      public function ejecutar()
      {
         //...  
      }
   }
}

Remove the%% mod% of the function so that it works for you:

class Conexion
{
   public function __construct()
   {

      function ejecutar()
      {
         //...  
      }
   }
}

But what you probably want is to access the method public by means of the instance, so take the declaration of the method out of the constructor:

class Conexion
{
   public function __construct()
   {

   }

    // declarada fuera del constructor
    public function ejecutar()
    {
         //...  
    }
}
    
answered by 28.04.2018 в 21:44