Solved

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\oop-beg\ch4-7.php on line 38

Posted on 2013-12-09
8
1,592 Views
Last Modified: 2013-12-09
<?php
class Person{}
class Vegetable{}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){}
  public function SmileAtYou(){}
  public function TalkToYou(){}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){}
  public function CauseBathroomEmergency(){}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $thingsThatMakeYouSweat=array($thing1,$thing2);
    SitAtBar($thingsThatMakeYouSweat);
  }
  void SitAtBar(){
    //when you are sitting at the Bar
    foreach($thingsThatMakeYouSweat as $value){
      
    }
  }
}

Open in new window


from an object oriented php tutorial

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\oop-beg\ch4-7.php on line 38

and how could an object be created and an object instance called
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
8 Comments
 
LVL 10

Assisted Solution

by:ienaxxx
ienaxxx earned 125 total points
ID: 39705943
...
  public function SitAtBar(){
....
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39705945
To create a new instance, after the ending brackets of the class:

$obj = new CollegeBar();

to call the object method SitAtBar:

$obj->SitAtBar();

Hope this helps
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39705951
Ah, this kind of error is probably because you are using a very old version of PHP (i guess it from the path, that contains WAMPP, instead of XAMPP. That name has been switched a lot of time ago).
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 125 total points
ID: 39706033
@ienaxxx: WAMP ( http://www.wampserver.com/en/ ) and XAMPP ( http://www.apachefriends.org/en/xampp.html ), are 2 separate packages, both actively maintained.

HTH,
Dan
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39706061
Uh, wow.

Sorry: i was sure xampp was the evolution of wampp...
:-(
then @rgb192 : can you post a phpinfo(), please?
0
 

Author Comment

by:rgb192
ID: 39706367
line 38:
public function SitAtBar(){

can 'void' be used because tutorial was an example of 'void'
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 250 total points
ID: 39706509
greetings  rgb192, , The programming term 'void' is used in other programming languages as a way to say the a "function" does not return a result, it returns nothing at all. However in PHP you can not use 'void', especially with a function as you did with -
void SitAtBar(){
    this is totally incorrect PHP syntax. It is posible that your tutorial was showing you a "Code" example in another language to help you, but you can not use 'void' in PHP.

I looked at your code example here, and it will not teach you much of anything about Class and Objects in PHP, why, because your parent Classes of-
class Person{}
class Vegetable{}

are EMPTY, you should have at least one property and one method in each, to see how this affects the Child Classes.

also your last Class-CollegeBar is SO BAD CODE, all kinds of Class thinking Errors, and php syntax - formatting errors, you should really be more knowledgeable about writing a PHP Class by now,you have -
class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $thingsThatMakeYouSweat=array($thing1,$thing2);
    SitAtBar($thingsThatMakeYouSweat);
  }
  void SitAtBar(){
    //when you are sitting at the Bar
    foreach($thingsThatMakeYouSweat as $value){
     
    }
  }
}

But you have left out the necessary method for ISweat as- MakeYouSweat()  and you have
  void SitAtBar(){
which should be
  public function SitAtBar($thingsThatMakeYouSweat){

<?php
class Person{public $name='none';
public function echoName(){echo $this->name;}
}
class Vegetable{public $type='none';
public function echoType(){echo $this->type;}
}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){echo $this->name.'=LookAtYou-';}
  public function SmileAtYou(){$this->echoName(); echo '=SmileAtYou-';}
  public function TalkToYou(){echo 'SmileAtYou-';}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
    return 'AttractiveStranger-MakeYouSweat';
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){echo $this->type.'=BurnYourTongue-';}
  public function CauseBathroomEmergency(){$this->echoType();  echo 'CauseBathroomEmergency-';}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
    return 'Pepper-MakeYouSweat';
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $arrayValues=array($thing1,$thing2);
    $this->SitAtBar($arrayValues);
  }
  public function SitAtBar($things){
    //when you are sitting at the Bar
    foreach($things as $value){
      echo $value.'-';
    }
  }

  public function MakeYouSweat(){
  echo 'Perspiration';
  }
}

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 39707573
Thanks for the echo information which I will have a new question on how to output by calling the object
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
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.

739 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