php-rest-api icon indicating copy to clipboard operation
php-rest-api copied to clipboard

syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE)

Open sanbroz opened this issue 3 years ago • 3 comments

http localhost/products

HTTP/1.1 500 Internal Server Error Connection: close Content-Length: 157 Content-Type: application/json; charset=UTF-8 Date: Sun, 11 Sep 2022 06:20:47 GMT Server: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.29 X-Powered-By: PHP/7.4.29

{ "code": 0, "file": "C:\xampp\htdocs\src\Database.php", "line": 5, "message": "syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE)" }

sanbroz avatar Sep 11 '22 06:09 sanbroz

This looks like a PHP version issue - if you're on a version prior to PHP8, you can't use constructor property promotion (adding visibility modifiers in the constructor arguments)

daveh avatar Sep 12 '22 10:09 daveh

Hi @daveh, great tutorial & nice work! thanks for sharing! But could you please provide the environment requirements such as which PDO drivers are needed to get the project works. I started with this tutorial on youtube & wanted to continue the full course with Authentication & so on on Udemy, but I am kind of stuck at this point, because contrary to you in your the main tuto I'm not using MAMP, I am using docker and I'm running PHP 8 with MariaDB 10.9.3 & I've PDO Sqlite with its library SQLite Library | 3.34.1 running & I got the message -> could not find driver","file":"/var/www/html/src/Database.php","line":16

corelus avatar Nov 01 '22 11:11 corelus

@corelus I'm actually using XAMPP, but the results should be the same. To use PDO with MariaDB you need to install the PHP MySQL package - on Linux this would be

sudo apt-get install php-mysql

for example

daveh avatar Nov 01 '22 18:11 daveh