Solved

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

Posted on 2013-12-09
3
369 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
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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now