10 Replies - 1864 Views - Last Post: 15 November 2012 - 07:24 PM Rate Topic: -----

#1 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

oops concept

Posted 15 November 2012 - 08:23 AM

I am getting the syntax error on line number 8
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/wd/public_html/beta/sangeetha/htmlfiles/class_lib.php on line 8

what is this T_FUNCTION ?

<html>
<head>
<?php include("class_lib.php"); ?>
</head>
<body>
<?php
   $stefan = new person("stefan Mischook");
    echo "Stefan's full name: ".$stefan->get_name();
	
	$james = new employee("Johnny Fingers");
                echo "---> " . $james->get_name();

	
	/*echo "Tell me private stuff: ".$stefan->pinn_number;
	
   $jimmy = new person;
   
   $stefan->set_name("stefan Mischook");
   $jimmy->set_name("Nick Waddles");
   
   echo "Stefan's full name: ".$stefan->name();
   
   echo "Nick's full name: " . $jimmy->get_name();*/
   
   
?>
</body>
</html>


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 15 November 2012 - 08:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: oops concept

#2 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Re: oops concept

Posted 15 November 2012 - 08:36 AM

Post your codes in [code] tags please.

It means it doesn't know one of the function. The function doesn't exist. The file you showed us does not contain the error, but it does include the file with the error (class_lib.php), so you will still see this error. You should show us class_lib.php.
Was This Post Helpful? 0
  • +
  • -

#3 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: oops concept

Posted 15 November 2012 - 08:39 AM

Edit:creativecoding beat me to it.

The error message says the error was encountered on line 8 on your class_lib.php file, so you'll need to post the code in that file as well. T_STRING and T_FUNCTION are, as the names suggest, strings and functions. The parser found a string (something like "test"), but it wanted a function(like get_name() ).

You might've added quotes in a wrong spot, but that's impossible to know without seeing the code

This post has been edited by Sho Ke: 15 November 2012 - 08:40 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6037
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: oops concept

Posted 15 November 2012 - 08:42 AM

It's copypasta. Probably didn't follow the rest of the tutorial from which it came.
Was This Post Helpful? 1
  • +
  • -

#5 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

Re: oops concept

Posted 15 November 2012 - 09:05 AM

<?php
   class person
   {
      var $name;
	    public $height;
		protected $social_insurance;
		private $pinn_number;
	  function_construct($persons_name)
	  {
	     $this->name=$persons_name;
	   }
      private function get_pinn_number()
       {
           return $this->pinn_number;	   
	  
	  function set_name($new_name)
	  {
	     $this->name = $new_name;
	  }
	  function get_name()
	  {
	     return $this->name;
	  }	 
	  
	  protected function set_name($new_name)
	  {
	    if(name!= "Jimmy Two guns")
		{
		   $this->name = strtoupper($new_name);
		 }
		 
		 
      
	}
	}
	}
	
	class employee extends person
	{
	   protected functio set_name($new_name)
	   {
	      if($new_name == "Stefan jones")
		  {
		      $this->name = $new_name;
		  }
		  else if($new_name == "Johny Fingers");
          {
              person::set_name($new_name);
          }  
       }
		
	   functio_construct($employee_name)
	   {
	      $this->set_name($employee_name);
		  }
		  }
		  
?>	





<html>
<head>
<?php include("class_lib.php"); ?>
</head>
<body>
<?php
   $stefan = new person("stefan Mischook");
    echo "Stefan's full name: ".$stefan->get_name();
	
	$james = new employee("Johnny Fingers");
                echo "---> " . $james->get_name();

	
	/*echo "Tell me private stuff: ".$stefan->pinn_number;
	
   $jimmy = new person;
   
   $stefan->set_name("stefan Mischook");
   $jimmy->set_name("Nick Waddles");
   
   echo "Stefan's full name: ".$stefan->name();
   
   echo "Nick's full name: " . $jimmy->get_name();*/
   
   
?>
</body>
</html>
   


Was This Post Helpful? 0
  • +
  • -

#6 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: oops concept

Posted 15 November 2012 - 09:20 AM

On line #8, notice how the function keyword isn't blue? Look at 8, 12, and 20. What pattern does 12 adn 20 follow that 8 doesn't?
Was This Post Helpful? 0
  • +
  • -

#7 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

Re: oops concept

Posted 15 November 2012 - 10:04 AM

ya i got it, it was white space thats why it wasn't blue
Was This Post Helpful? 0
  • +
  • -

#8 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

Re: oops concept

Posted 15 November 2012 - 11:24 AM

This is a real world example code.. but i am getting the error
Fatal error: Cannot redeclare class twitter in /home/wd/public_html/beta/sangeetha/htmlfiles/twitter.php on line 4
<?php

class twitter 
{

	public $twitter_base = 'http://twitter.com/statuses';
	public $twitter_username = 'sangeetha'; //Your username here

  function latest()
  {       

		$url = "$this->twitter_base/user_timeline/$this->twitter_username.xml?count=1";
		$content = file_get_contents($url);

		$xml = new SimpleXMLElement($content);
		$status_item = $xml->status;

		$status =  $status_item->text;
		return $status;

	}

}
?>




This is a real world example code.. but i am getting error
Fatal error: Cannot redeclare class twitter in /home/wd/public_html/beta/sangeetha/htmlfiles/twitter.php on line 4

here is the class code
<?php

class twitter 
{

	public $twitter_base = 'http://twitter.com/statuses';
	public $twitter_username = 'sangeetha'; //Your username here

  function latest()
  {       

		$url = "$this->twitter_base/user_timeline/$this->twitter_username.xml?count=1";
		$content = file_get_contents($url);

		$xml = new SimpleXMLElement($content);
		$status_item = $xml->status;

		$status =  $status_item->text;
		return $status;

	}

}
?>




here is the html
<?php
require('twitter.php');

$twitter = new twitter();

?>

<html>
	
	<body>
 		<?php echo $twitter->latest(); ?>
	</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,045
  • Joined: 08-June 10

Re: oops concept

Posted 15 November 2012 - 02:24 PM

View Postsangeetha_s, on 15 November 2012 - 07:24 PM, said:

This is a real world example code.. but i am getting the error
Fatal error: Cannot redeclare class twitter in /home/wd/public_html/beta/sangeetha/htmlfiles/twitter.php on line 4

What do you suggest could the phrase "cannot re-declare class" mean? its not that PHP is particularly cryptic here.
Was This Post Helpful? 0
  • +
  • -

#10 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

Re: oops concept

Posted 15 November 2012 - 06:05 PM

Its the copy paste code just to try how it works but then also i am getting error
Was This Post Helpful? 0
  • +
  • -

#11 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: oops concept

Posted 15 November 2012 - 07:24 PM

We're not just going to feed you the answer. The error says you cannot redeclare a class, which means a class is being declared twice. What can you do about that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1