Class Parse Error Syntax Error Unexpected T_string Expecting T_function
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or syntax error, unexpected (t_string), expecting function (t_function) posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss php expecting function (t_function) Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes syntax error unexpected print_r t_string a minute: Sign up PHP class — Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION up vote 0 down vote favorite I have a php class code like this: class Foo{ const ERROR_CODE = '404'; public $public_ex = 'this is
Parse Error: Syntax Error, Unexpected ';', Expecting Function (t_function)
public'; private $private_ex = 'this is private!'; protected $protected_ex = 'this should be protected'; public function getErrorCode() { return self::ERROR_CODE; } } $foo = new Foo; $foo_json = json_encode($foo); echo $foo_json; And it shows: Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in xxx.php on line 4 What should I do to make it run? Thank you very much!! > < php class syntax-error share|improve this question asked Nov 3 '14 at 11:28 Elsa 246 Cannot replicate the error you've syntax error unexpected 'echo' (t_echo) give with the code provided. Unless you're running <5, but then again, not the same error. –ʰᵈˑ Nov 3 '14 at 11:29 Which line is #4 in the original file? There are no problems associated with your private variable example as listed above. Is this the entire file or just part of it? –Maxim Kumpan Nov 3 '14 at 11:31 I tried your code and it works for me... is the parse error in this code or in a different file? which file is xxx.php? –Ares Draguna Nov 3 '14 at 11:36 Show us your xxx php, because the code you posted is valid php code. –karacsi_maci Nov 3 '14 at 11:42 It's the code of xxx.php...Orz It seems like it only doesn't work for me..(?) T_T –Elsa Nov 4 '14 at 2:29 add a comment| active oldest votes Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook. Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Browse other questions tagged php class syntax-error or ask your own question. asked 1 year ago viewed 601 times Related 1PHP Parse error: syntax error, unexpec
here for a quick overview of the site Help Center Detailed parse error: syntax error, unexpected ':' in answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss http://stackoverflow.com/questions/26713303/php-class-parse-error-syntax-error-unexpected-t-string-expecting-t-functio Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up unexpected T_STRING, expecting T_FUNCTION [closed] up vote 0 down vote favorite Just learning how to work with php and mysql, http://stackoverflow.com/questions/10704705/unexpected-t-string-expecting-t-function using CodeIgniter. Running into that error. I am attempted to check login attempts against my database, where they are stored. Here are the related functions in my login model: public function verify_user($email, $password) { $q = $this ->db ->where('email_address', $email) ->where('password', $password) ->limit(1) ->get('users'); if ($q->num_rows > 0) return $q->row(); } add_login_attempt($email); return false; } public function add_login_attempt($email) { $current_attempts = get_login_attempts($email); if ($current_attempts > 2) { lock_account($email); } else { $updated_attempts = $current_attempts + 1; $data = array('login_attempts' => $updated_attempts); $this->db->where('email_address', $email); $this->db->update('crm', $data); } } function reset_login_attempts($email) { } function lock_account($email) { } public function get_login_attempts($email) { $this->db->select('login_attempts'); $this->db->from('crm'); $this->db->where('email_address', $email); $login_attempts = $this->db->get(); return $login_attempts; } } Logging in using correct credentials works no problem. When an incorrect password is entered, that error is encountered. Any help is greatly appreciated. php mysql codeigniter share|improve this question edited May 22 '12
PHP Forum View Course 508 points Submitted by bobfleming almost 3 years ago 5/10 Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE on https://www.codecademy.com/en/forum_questions/52bb7913548c35e324005ed6 line 16 In both 5/10 and 6/10 I ge the following parsing https://www.experts-exchange.com/questions/28313720/Parse-error-syntax-error-unexpected-T-STRING-expecting-T-FUNCTION-in-C-wamp-www-oop-beg-ch4-7-php-on-line-38.html error: Parse error: syntax error, unexpected TSTRING, expecting TVARIABLE on line 16 This is line 16: public function_construct($firstname, $lastname, $age) { I can't find anything wrong. I know what strings and variables are, but what does the prefix "T" indicate in the error message? Despite the message, syntax error the m\code passes to go on to the next exercise, but there is no output. I am using the code from 1/10 as a guide, along with instructions and hints, and everything in my code looks right! $frustration = "unresolved errors!"; My complete code follows:
syntax error unexpected firstname = $firstname; $this->lastname = $lastname; $this->age = $age; public function $greet() { return "Hello, my name is " . $this->firstname . " " . $this->lastname . '. nice to meet you! :-)"; } } $teacher = new Person ("boring", "12345"' 12345); $student = new Person ("Bob", "Fleming", 77); echo greet($teacher); echo greet($student); echo $student->age; ?>
0 votes permalink Something I forgot to point out in my question above -- I see nothing in my constructor that looks anything like a string (enclosed in ' ' or " ")!!! One more thing is that since I posted my question I worked through the remaining exercises up through 10/10, and I got the same parsing error on the constructor in all of them, and none of them went, but all of them gave the "Way to go! and the green "Start next lesson" button. Go figure! This could be a bug in the parsing codfor Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\oop-beg\ch4-7.php on line 38 Want to Advertise Here? 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 PHP 3 Verified Solutions 8 Comments 1,312 Views Last Modified: 2013-12-09 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){ } } } Select all Open in new window from an object oriented php tut