osherdo Posted August 20, 2016 Share Posted August 20, 2016 I have this code: class DropzoneController extends Controller { public function __construct() { $this->middleware('auth'); if (!Auth::check()) { return redirect('auth/login'); } $this->user = Auth::user(); } public function index() { return view('dropzone_demo'); } public function uploadFiles() { $message="Profile Image Created"; $input = Input::all(); $rules = array( 'file' => 'image|max:3000', ); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Response::make($validation->errors->first(), 400); } $destinationPath = 'uploads'; // upload path: public/uploads $extension = Input::file('file')->getClientOriginalExtension(); // getting file extension $fileName = rand(11111, 99999) . '.' . $extension; // renameing image $upload_success = Input::file('file')->move($destinationPath, $fileName); // uploading file to given path if ($upload_success) { return Response::json('success', 200); } else { return Response::json('error', 400); } // attaching the profile image to the authenticated user. $user->profileImage()->create([ 'filename' => $filename ]); Session::flash('new_profile_image', 'Profile Photo Updated!'); } public function authorize($ability, $arguments = Array) { // set to true instead of false return true; } } The error occurs for this line: public function authorize($ability, $arguments = Array) and it says: syntax error, unexpected ')', expecting '(' Not sure what that means. Anyone who can tell me what the issue is? Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/ Share on other sites More sharing options...
Solution requinix Posted August 20, 2016 Solution Share Posted August 20, 2016 If you want to make sure $argument is an array then you need public function authorize($ability, array $arguments)If you want the default value to be an empty array then you need public function authorize($ability, $arguments = array())If you want both - which I suspect is the case - then do both. Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536358 Share on other sites More sharing options...
osherdo Posted August 20, 2016 Author Share Posted August 20, 2016 If you want to make sure $argument is an array then you need public function authorize($ability, array $arguments)If you want the default value to be an empty array then you need public function authorize($ability, $arguments = array())If you want both - which I suspect is the case - then do both. It seems that only this works: public function authorize($ability, $arguments = array()) because using the other one, or using them both as an arguments returns this error: (I am using Laravel, and it returns this) Declaration of App\Http\Controllers\DropzoneController::authorize() should be compatible with App\Http\Controllers\Controller::authorize($ability, $arguments = Array) I am now getting an error of Laravel, so that'll do for now. much thanks! Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536359 Share on other sites More sharing options...
Jacques1 Posted August 20, 2016 Share Posted August 20, 2016 The “array()” syntax is obsolete. Use “[]” instead. The reason why you cannot add the array type hint is because the method you're overriding doesn't have it. Otherwise it would be perfectly valid. Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536361 Share on other sites More sharing options...
requinix Posted August 20, 2016 Share Posted August 20, 2016 The “array()” syntax is obsolete.No it is not. Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536366 Share on other sites More sharing options...
Jacques1 Posted August 20, 2016 Share Posted August 20, 2016 Yes, it is. PHP 5.3 is long dead, so the short array syntax is now available everywhere. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536368 Share on other sites More sharing options...
requinix Posted August 20, 2016 Share Posted August 20, 2016 Yes it is now available to everyone. But that doesn't mean the original "array()" syntax is obsolete. Nor is it discouraged, nor is "[]" a best practice, nor is really anything true besides there being two array syntaxes available. Frankly, I think [] gets lost in the mess of other symbols too easily. It's sure handy for writing an array but sometimes I like seeing the word "array" for clarity. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536375 Share on other sites More sharing options...
osherdo Posted August 20, 2016 Author Share Posted August 20, 2016 unfortunately using this: [] returns an error: syntax error, unexpected '[', expecting '(' Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536376 Share on other sites More sharing options...
Jacques1 Posted August 20, 2016 Share Posted August 20, 2016 Sounds like you've tried “array[]”. That's not what I said. I'm talking about replacing “array()” with the new array literal “[]”. So instead of the keyword “array” followed by a pair of parentheses, it's now just a pair of square brackets without any “array” keyword, just like in JavaScript (or Ruby, Python, ...). If you're still not sure how the correct syntax looks like, read the manual. Frankly, I think [] gets lost in the mess of other symbols too easily. It's sure handy for writing an array but sometimes I like seeing the word "array" for clarity. You can like whatever you want. I'm sure there are also people who like to write $a{$i} instead of $a[$i], and that's fine as long as nobody bothers to officially deprecate or remove this syntax. The point is that instead of the old, verbose PHPism “array(...)”, there's now a literal syntax which is compact, easy to read and consistent with other languages. The PSR documents use it (even though it's not officially endorsed), Laravel uses it, and just about every other big project has at least considered using it. The only reason why this hasn't always happened is because of legacy code. Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536378 Share on other sites More sharing options...
osherdo Posted August 23, 2016 Author Share Posted August 23, 2016 @OrpheanBeholderScryDoubt thanks for the suggestion and reference. Good to know about it. Quote Link to comment https://forums.phpfreaks.com/topic/301949-syntax-error-unexpected-expecting/#findComment-1536517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.