Solved

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

Posted on 2013-12-09
3
372 Views
Last Modified: 2013-12-10
<?php
class MyClass{
  public function doSomething(){
    $filename='test.txt';
    try{
      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>';
    }
    finally{
      //create the file if it does not exist
      $handle=fopen($filename,'w');
      fclose($handle);
    }
  }
}
$test=new MyClass();
$test->doSomething();

Open in new window


Parse error: syntax error, unexpected '{' in C:\wamp\www\oop-beg\ch6-2.php on line 15
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39707737
What version of PHP are you running? finally is available in PHP 5.5 and up.

http://php.net/exceptions
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39708253
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

0
 

Author Closing Comment

by:rgb192
ID: 39708587
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
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question