• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Parse error: syntax error, unexpected '{' in C:\wamp\www\oop-beg\ch6-2.php on line 15

class MyClass{
  public function doSomething(){
      if (!file_exists($filename)){
        throw new Exception("file does not exist");
    catch (Exception $e){
      //handle/report exception
      echo '<br>exception caught: '.$e->getMessage().'<br>';
      echo '<br>exception code: '.$e->getCode().'<br>';
      //create the file if it does not exist
$test=new MyClass();

Open in new window

Parse error: syntax error, unexpected '{' in C:\wamp\www\oop-beg\ch6-2.php on line 15
1 Solution
käµfm³d 👽Commented:
What version of PHP are you running? finally is available in PHP 5.5 and up.

Ray PaseurCommented:
This is one of those places where OOP doesn't really fit well.  The goal appears to be (1) look for a file; (2) issue a message if the file does not exist; (3) create an empty file or truncate the existing file.

<?php // RAY_temp_rgb192.php

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28314450.html

$file = 'temp_rgb192.txt';
if (!file_exists($file)) echo "<b>$file</b> does not exist (yet)";
$fpr  = fopen($file, 'w');
fclose ($fpr);

Open in new window

rgb192Author Commented:
finally in php5.5 and up.

This would take me a long time to test

I should figure out a way to have php5.5 on my machine
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now