Execute variable contained function name (PHP)

Asked

Viewed 20 times

0

I am mounting an application that executes a function with its own name In case the Contact page would have to perform the Contactoctl() function only it is in a $method variable. How would I perform this function?

$ctlclass = 'Contato';
$metodo = $ctlclass.'Ctl()';
$this->$metodo;

ABOVE CODE RETURNS THE FOLLOWING ERROR:

Fatal error: Uncaught Error: Using $this when not in Object context in C: xampp htdocs Aplication Contato.php

1 answer

2

The $this is a Pseudo-variable of PHP, it works different from other variables, and who manipulates it is the virtual machine of PHP. The $this points to an object in memory, that is, the object that is running. Looking at your code snippet, apparently you’re not in a class, so you won’t be able to use the $this.

  • I figured this could be the problem, only how I would perform the Contactoctl function() ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.