Unexpected T_VARIABLE, expecting T_FUNCTION 4

2.1k views Asked by At

I keep getting the following error in PHP:

Parse error: syntax error, unexpected '$date' (T_VARIABLE), expecting function (T_FUNCTION) in your code on line 3

With the following code:

<?php
 require("/edconfig.php");
 class EasyDevop{
  $date = new DateTime();
  $date->format('Y-m-d H:i:s');
  function dataLog($dataLog=""){
   file_put_contents($fileLog, $dataLog);
  }
  function newPage($filedirnametype=""){
   if(!file_exists($filedirnametype)){
    $handleFile = fopen($filedirnametype, "w");
    dataLog($filedirnametype."; ".$date."\n");
   } else{
    echo "<b>Unable to create your page! It possibly already exists.</b>";
   }
  }
 }
?>

And I have tried everything, but I simply can't get it fixed. Can anyone please help me?

I'm new to PHP OOP.

1

There are 1 answers

0
alu On BEST ANSWER

Take a look at object-orientated programming in the official PHP documentation: http://php.net/manual/en/language.oop5.php