googleads-php-lib icon indicating copy to clipboard operation
googleads-php-lib copied to clipboard

Parse error: syntax error, unexpected '?', expecting variable

Open steponafish opened this issue 8 years ago • 24 comments

Hello. I found a thread on Google Groups to use this repository for this issue. In that thread it was said that the PHP library requires 5.5.9 or higher. I'm currently running on 7.0.29 and I'm still getting this error.

I'm getting this error: Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/........./wp-content/themes/clientTheme/adwords/symfony/serializer/Normalizer/AbstractObjectNormalizer.php on line 238

I got this error when testing out the DownloadCriteriaReportWithAwql.php file. I took a look at line 238 in the AbstractObjectNormalizer file just to see and it's a line that's been commented out.

Any help or advice?

steponafish avatar May 11 '18 19:05 steponafish

Could you tell what is the version of Symfony serializer you have installed?

fiboknacky avatar May 12 '18 04:05 fiboknacky

The Changelog in the Symfony directory says 4.0.0

steponafish avatar May 13 '18 15:05 steponafish

OK. Symfony Serializer v4.0.0 needs PHP v7.1.3. This is probably the cause why you see an error because there might be some syntax that your PHP version doesn't recognize.

fiboknacky avatar May 14 '18 01:05 fiboknacky

So what do I do? I cannot increase my php version. I am using 7.0.29

On Sun, May 13, 2018 at 7:23 PM Thanet Knack Praneenararat < [email protected]> wrote:

OK. Symfony Serializer v4.0.0 needs PHP v7.1.3. This is probably the cause why you see an error because there might be some syntax that your PHP version doesn't recognize.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/googleads/googleads-php-lib/issues/489#issuecomment-388672064, or mute the thread https://github.com/notifications/unsubscribe-auth/AIP3gOXV2xmp_exYYaStZqf6gEi_Njlxks5tyNx9gaJpZM4T78-8 .

steponafish avatar May 14 '18 01:05 steponafish

How did you install Symfony serializer? Is it installed via other libraries by composer? I can't see your project directory structure so I can't advice more. Could you explain in detail what libraries do you use and what does your composer.json look like?

fiboknacky avatar May 14 '18 04:05 fiboknacky

I downloaded the entire adwords api via composer. I did this two weeks ago.

composer require googleads/googleads-php-lib

On Sun, May 13, 2018 at 10:39 PM Thanet Knack Praneenararat < [email protected]> wrote:

How did you install Symfony serializer? Is it installed via other libraries by composer? I can't see your project directory structure so I can't advice more. Could you explain in detail what libraries do you use and what does your composer.json look like?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/googleads/googleads-php-lib/issues/489#issuecomment-388695144, or mute the thread https://github.com/notifications/unsubscribe-auth/AIP3gIsNDo6J7q6aUJvdS64zJrpWNxNuks5tyQqJgaJpZM4T78-8 .

steponafish avatar May 14 '18 14:05 steponafish

Could you please answer all my previous questions in the previous reply? This will save us turn-around time and it would lead us to the solution more quickly. The more details you could provide, the faster I can understand your circumstances. Thanks. :)

fiboknacky avatar May 14 '18 15:05 fiboknacky

How did you install Symfony serializer? and Is it installed via other libraries by composer? I installed Symfony and the the rest of the googleads-php files via Composer and then I moved them to my webhost environment via FTP. I cannot install it otherwise onto my webhost.

Could you explain in detail what libraries do you use and what does your composer.json look like? I'm not sure what libraries I use because I haven't finished the project. This project will be a custom dashboard for clients to see their own data. Right now I'm trying to use one of the reporting sample DownloadCriteriaReportWithAwql to view an XML or CSV string and it's throwing me the error above.

Attached is a screenshot of the composer.json found in the Symfony directory. screen shot 2018-05-14 at 9 16 41 am

steponafish avatar May 14 '18 15:05 steponafish

Thanks for the information. I meant your project's composer.json, not the Serializer's composer.json. Could you share that too?

fiboknacky avatar May 14 '18 15:05 fiboknacky

Here's the project's composer.json. I have not changed anything in this file since downloading via composer. screen shot 2018-05-14 at 9 39 26 am

steponafish avatar May 14 '18 15:05 steponafish

Hmm.. Everything should be alright. Can you try, in your local machine, removing the vendor/ directory, run composer install, and try again?

fiboknacky avatar May 14 '18 15:05 fiboknacky

Just to let you know, these files are from my web host. So do I need to redo everything?

steponafish avatar May 14 '18 15:05 steponafish

At least, you would need to try in the local machine first. I wonder why composer install a dependency that is not compatible with your PHP version.

If you have developed something in your project file, you can try on a clean directory first. By the way, you would need to use the same PHP version (7.0) as your web host too.

fiboknacky avatar May 14 '18 15:05 fiboknacky

I just redownloaded the vendor files. How do I check to see if they are for PHP 7.0?

steponafish avatar May 14 '18 15:05 steponafish

Just run what you originally ran to get the error message, probably DownloadCriteriaReportWithAwql? Also, you can check the Serializer version by yourself. You can use that to check with Serializer GitHub repo to see its composer.json

fiboknacky avatar May 14 '18 16:05 fiboknacky

I was able to successfully run it on my local machine. I'm going to upload all the files to my webhost and test it there.

steponafish avatar May 14 '18 16:05 steponafish

So I checked the php version on my local machine compared to the one in my webhost. Local Machine is at php version 7.1.14 and my webhost is 7.0.29. I redownloaded everything to my webhost and I'm going to safely assume it's my php version because now I'm getting a: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/........../wp-content/themes/clientTheme/adwords/symfony/serializer/Normalizer/AbstractObjectNormalizer.php on line 238

steponafish avatar May 14 '18 16:05 steponafish

So, there's no other way. If you need to install via local machine and copy files over to the host, you need to find a machine that have the same PHP version as your web host. Alternatively, you could install Symfony serializer by yourself by doing the following:

  • Remove only symfony/serializer in your vendor/
  • Run composer require symfony/serializer:3.1

Then copy newly created symfony/serializer over to the vendor/ directory in your web host.

fiboknacky avatar May 15 '18 03:05 fiboknacky

Is that serializer version compatible to php v7.0?

steponafish avatar May 15 '18 15:05 steponafish

You can check by yourself by checking the require part of composer.json of any projects.

fiboknacky avatar May 15 '18 16:05 fiboknacky