<?
class Contact {
//protected $message = "Hello World";
function __construct($message){
echo $this ->message;
}
function getName() {
}
}
$con = new Contact("Hello World");
?>
<form method="post" action="Contact.php">
- When i compile this class, its not printing “Hello World” Why?
- How can i call the getName() function in my form action. Is the below right way.
<form method="post" action={$con->getName()}>
A) You don’t compile PHP
B)
$messageisn’t an instance variable, it’s a parameter:The way you inject your PHP method calls into HTML:
Your commented out
//protected $message = "Hello World"is on the right track. Something like this would be ideal:Used like so: