Php Syntax Error Unexpected T_array
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 parse error: syntax error, unexpected 'array' (t_array) company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
T_array Oracle
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million
Php Unexpected ;
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP: What's the difference between initializing an array with “new” vs without it? up vote 11 down vote favorite 5
Php Array Declaration
I've always created arrays by just populating them $foo[] = 'car'; but I've seen a lot of $foo = array(); $foo[] = 'car'; and $foo = new array(); What's the difference between not initializing, using array(), and using new array();? thanks! php arrays initialization share|improve this question asked Nov 16 '10 at 19:50 mattypie 61114 add a comment| 4 Answers 4 active oldest votes up vote 18 down vote accepted You don't instantiate an array in PHP using: $foo=new array(); // error in PHP That's for Javascript: foo=new Array(); // no error in Javascript In PHP, new is used only for instantiating objects. share|improve this answer edited Nov 16 '10 at 20:00 answered Nov 16 '10 at 19:55 stillstanding 12.8k22544 1 Makes sense, thanks! –mattypie Nov 16 '10 at 20:06 3 +1. Just like to point out that "In PHP, new is used only for instantiating objects."... In Javascript too, it's just that Array is an object in Javascript, while in PHP, it's an ordered map (something Javascript does not have per say, because an ordered map in JS is an object). –netcoder Nov 16 '10 at 20:11 You're absolutely right. Associative arrays in Javascript are objects. –stillstanding Nov 16 '10 at 20:19 add a comment| up vote 9 down vote The difference is that using new does not work, since array() is a language construct and not an object constructor. It throws an error: Parse error: syntax error, unexpected T_ARRAY in php shell code on line 1 On the other hand, declaring it like $f=array(); before you start assigning items is a good practice. Strict error reporting mode may give a warning about using an undeclared variable otherwise. share|improve this answer answered Nov 16 '10
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 posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Wordpress: Parse error: syntax error, unexpected 'array' (T_ARRAY) site http://stackoverflow.com/questions/4198300/php-whats-the-difference-between-initializing-an-array-with-new-vs-without-i broken [closed] up vote -4 down vote favorite new here and a bit of a noob. was trying to add a field to a custom post type and ended up with a parse error message on all website pages. I've pasted the error message and the contractor-type.php code can anyone tell me how to fix this? I've had no luck reaching the hosting provider to do a full http://stackoverflow.com/questions/19031871/wordpress-parse-error-syntax-error-unexpected-array-t-array-site-broken restore. Thanks very much for any and all suggestions. I don't have ftp access at the moment all ive been able to do is use the file manager in the hosting control panel to try to upload backed up copies of the theme files to no avail. Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' in /home/renovant/public_html/wp-content/themes/renovantage/self-developed-plugin/contractor-type.php on line 212 post_title; foreach($infos as $key => $vls) { $return[$key] = $vls[0]; } return $return; } add_action( 'init', 'tr_contractor_type' ); function tr_contractor_type() { $labels = array( 'name' => _x('Contractors', 'post type general name'), 'singular_name' => _x('Contractor', 'post type singular name'), 'add_new' => _x('Add New Contractor', 'article'), 'add_new_item' => __('Add New Contractor'), 'edit_item' => __('Edit Contractor'), 'new_item' => __('New Contractor'), 'view_item' => __('View Contractor'), 'search_items' => __('Search Contractor'), 'not_found' => __('No Contractors found'), 'not_found_in_trash' => __('No Contractors found in Trash'), 'parent_item_colon' => '' ); $supports = array( 'title', // 'editor', //'author', 'thumbnail', //'excerpt', // 'comments', // 'custom-fields', // 'trackbacks', 'revisions' ); $args = array( 'labels' => $labels, 'public' => true, 'capability_type' => 'post', 'supports' => $supports, 'rewrite' => array( 'slug' => 'contractor','with_front' => false ),
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 http://stackoverflow.com/questions/24036046/php-syntax-error-unexpected-in-using-an-array site About Us Learn more about Stack Overflow the company Business Learn more https://www.drupal.org/node/654194 about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP syntax error, syntax error unexpected '[' in using an array [duplicate] up vote 4 down vote favorite This question already has an answer here: Access an Array Returned by a Function [duplicate] 6 answers I am using this code below : $data = array(); $value = reset($value); $data[0] = (string) $value->attributes()['data']; ------^ I have no problem in localhost, but in other host, when i check the code, i php syntax error see this error : Parse error: syntax error, unexpected '[' in .... I have shown where the code causes error . i have also used : $data[] = (string) $value->attributes()['data']; (without 0 in []) How can i solve it ? php share|improve this question asked Jun 4 '14 at 11:21 Cab 55110 marked as duplicate by Tim Cooperphp Users with the php badge can single-handedly close php questions as duplicates and reopen them as needed. Jun 4 '14 at 11:24 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 7 The issue is not with the first square brackets, it's with the ones after attributes(). –Tim Cooper Jun 4 '14 at 11:22 5 It's got nout to do with that first [, it's your function array dereferencing (the last []). You need PHP >= 5.4. –Prisoner Jun 4 '14 at 11:22 add a comment| 2 Answers 2 active oldest votes up vote 7 down vote accepted Array Referencing was first added in PHP 5.4. The code from PHP.net:
that make connections all over the world. Join today Download & Extend Drupal Core Distributions Modules Themes ChatroomIssues Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in chatroom.theme.inc on line 145 Closed (fixed)Project:ChatroomVersion:6.x-2.7Component:CodePriority:NormalCategory:Bug reportAssigned:UnassignedReporter:sri20198Created:December 8, 2009 - 10:22Updated:December 25, 2009 - 20:00 Log in or register to update this issue When I upload the Chatroom module to my site, I get the following error (I am not able to browse to any page): Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /sites/all/modules/chatroom/chatroom.theme.inc on line 145 The line 145 in chatroom.theme.inc reads: function theme_chatroom_messages(array $messages, $node) { I am using Drupal 6.14 with Chatroom 6.x-2.7. How to fix this? Am I missing anything? Comments Comment #1 beejeebus CreditAttribution: beejeebus commented December 9, 2009 at 7:17pm what version of php are you using? can you try changing that line to: function theme_chatroom_messages($messages, $node) { and let me know if that works? Log in or register to post comments Comment #2 sri20198 CreditAttribution: sri20198 commented December 11, 2009 at 7:54pm I am using PHP 5.2.5. I changed that line like you said, and its working now. Thanx so much. Sridhar Log in or register to post comments Comment #3 sri20198 CreditAttribution: sri20198 commented December 11, 2009 at 7:57pm Status: Active » Fixed Log in or register to post comments Comment #4 December 25, 2009 at 8:00pm Status: Fixed » Closed (fixed) Automatically closed -- issue fixed for 2 weeks with no activity. Log in or register to post comments Add child issue, clone issue News itemsDrupal news Planet Drupal Association news Social media directory Security announcements Jobs Our communityCommunity Getting involved Services, Training & Hosting Groups & Meetups DrupalCon Code of conduct DocumentationDocumentation Drupal 8 docs Drupal 7 docs Developer docs api.drupal.org Drupal code baseDownload & Extend Drupal core Modules Themes Distributions Governance of communityAbout Web accessibility The Drupal Association About Drupa