ursus contionabundo: PHP - Function wird nicht geschreibt

Beitrag lesen

Versuche herauszubekommen, was das folgende Skript macht.

<?php
class ClassProveContakt3 {

      private $Name     = '';
      private $Email    = '';
      private $Message  = '';
      private $PostOk   = false;
      private $DateTime = false;
      private $items    = false;

      function __construct() {
      
          $this -> DateTime = date('m/d/Y h:i:s a');
          $this -> items = ['Name', 'Email', 'Message'];  
          
          $flag = true;
          foreach ( $this -> items as $key ) {
			        if ( empty ( $_POST[$key] ) )  {
			            $flag = false;
			        } else {
			           $this -> $key = trim( filter_var( $_POST[$key], FILTER_SANITIZE_STRING ) );
			       }
		      }	    
          $this -> PostOk = $flag;
      }
  
      function ShowForm() {

        echo
          '<label for="Name">Name </label><input type="text" name="Name" id="Name" value="' . htmlspecialchars( $this -> Name ) . '"><br>'
        . '<label for="Email">Name</label><input type="email" name="Email" id="Email" value="' . htmlspecialchars( $this -> Email ) . '"><br>'
        . '<label> Message: </label><br><textarea cols="45" rows="6" name="Message">'. htmlspecialchars( $this -> Message ) . '</textarea>'
        . '<br><br>'
        . '<input type="submit" name="post" value="POST COMMENT" id="comment">';
      }

      function ShowData () {
          if( $this -> PostOk ) {
          
             $ShowItems = $this -> items; 
             $ShowItems[] = 'DateTime';
             
             echo '<table><tr>';
             foreach ( $ShowItems as $ColName ) {
                 echo"<th>" . htmlspecialchars( $ColName ) . "</th>";
             }
             echo '</tr><tr>';
             
             foreach ( $ShowItems as $ColName ) {
    			      echo"<td>" . htmlspecialchars( $this -> $ColName ) . "</td>";
    	       }
             echo "</tr></table>";
         } else {
             echo '<h3>*** Please enter all required fields ***</h3>';
         }
      }
} 
### End of the class
######################################################################

### Test ###
error_reporting( E_ALL );
header('Content-Type: text/html; Charset=utf-8');
mb_internal_encoding( 'UTF-8' );
date_default_timezone_set( 'Europe/Paris' );


### Data for Testing:
### Remove all or only the first '#' in '#/*' for real data.
#/*
$_POST['Name']    = "Hein Stein";
$_POST['Email']   = "hein@stein.ch";
$_POST['Message'] = "E=M*C²";
#*/


$objekt = new ClassProveContakt3();
######################################################################
?>
<html>
<head>
<style>
table, th, td {
   border: 1px solid black;
   border-collapse: collapse;
}

th {
    font-weight: bold;
    text-align: left;
}
</style>
</head>
<body>
<h1>Formular:</h1>
<?php $objekt -> ShowForm(); ?>
<h1>Daten:</h1>
<?php $objekt -> ShowData(); ?>
</body>
</html>