Solved

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

Posted on 2013-12-09
3
368 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 74

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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

13 Experts available now in Live!

Get 1:1 Help Now