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,459 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
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
 
LVL 34

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
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.

 
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 33

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

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

930 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

8 Experts available now in Live!

Get 1:1 Help Now