?
Solved

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

Posted on 2013-12-09
3
Medium Priority
?
374 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 2000 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 111

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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 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