Parse error: syntax error in PHP? [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi guys I'm following this tutorial and I'm getting an extremely strange error message in my PHP when I try and run it in the web browser. The code is as follows:
<?php
// Pull in the NuSOAP
require_once('nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
//(MyService is name of our service)
$server----->configureWSDL('MyService', 'urn:MyService');
// Character encoding
$server->soap_defencoding = 'utf-8';
//-------------------------------------------------
//Registrations of our functions
//-------------------------------------------------
//Our web service functions will be here.
//-------------------------------------------------
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Which is exactly as it's written in the tutorial, yet I keep getting this error message every time I run the PHP file:
UPDATE now I'm getting this error
Parse error: syntax error, unexpected T_DEC in
/home/a1335235/public_html/MyService.php on line 8
Can anyone figure out why?

As Mark Baker said in the comments (and I'll delete this if he posts first), your code is:
code require_once();
First and foremost code is not PHP. This should be require_once and you can see this in the PHP Manual. Secondly, require_once is a language construct. It's not a function call, so you don't need the (). You should have:
require_once 'nusoap.php';
The syntax error is telling you exactly what line the problem is on, so read it and google that bit of code to see how others are doing it and where you are going wrong in the future.
Now your issue is on line 8:
$server----->configureWSDL
This is not valid PHP either, unless you've heavily modifed the source code of the language, which you haven't. Change this to:
$server->configureWSDL()
That's how you call methods on objects. You should be reading the manual on Objects to see how this works.

Related

mkdir() returns No such file or directory in <b>...</b> on line <b>..</b><br /> [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm PHP developer but i cant understand this error
$uid = $this->db->Tables("telegrambots")->search([
"telegrambotid" => $this->botKey
])['uniqueId'];
if (!file_exists("TelegramBotCommands/{$uid}"))
mkdir("TelegramBotCommands/{$uid}");
Eval is evil, you probably don't need it so don't use it. You want to make a call to a class with a dynamic name? Use this:
$dynamic_class_name = 'Video';
$video = new $dynamic_class_name();
That being said, your snippet with eval seems to work perfectly fine:
http://sandbox.onlinephpfunctions.com/code/e3bb43b1ccfd27365247120e9c5751aac9e2b4ce
You would have to check your logs as to what the error is.
EDIT:
As you said you are using namespaces, try to use the full classname including the namespace in the eval function (like new \namespace\Videos(.... Even better though: don't use eval!

Fatal error: Function name must be a string whilst it shouldn't [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have stumbled over the following error in PHP:
"Fatal error: Function name must be a string in
F:\Applications\xampp\htdocs\BTB_Sandbox\uploads.php on line 15"
and I don't know what the real problem is. Here is line 15 that the error is pointing at:
$error = $_FILES(['file_upload']['error']);
I hope you could help me, because I am kind of stuck now.
You are using $_FILES as a function because of ().
That way, PHP tries to call a function named as var $_FILES value, but this value it not a string (that's the error reported), it is an array.
Obviously, in your code line you are failing to use $_FILES, the right way is:
$error = $_FILES['file_upload']['error'];

Weird PHP "Fatal error: Cannot redeclare" Error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My script is returning the following error...
Fatal error: Cannot redeclare connecttodatabase() (previously declared in /var/www/api/connecttodatabase.php:4) in /var/www/api/connecttodatabase.php on line 6
And the following is the connecttodatabase.php file...
<?php
function connecttodatabase()
{
$con = #mysqli_connect("localhost", "name", "password", "database");
return $con;
}
?>
I don't really understand this error because line 6 is just the closed curly bracket (})
I think the error means that it thinks I declared the function connecttodatabase() in to different spots but clearly I didn't.
As others have said in the comments, this is most likely because you have included connecttodatabase.php twice in your code, and you are certainly defining the function twice. Don't get hung up why it's line 6; line 2 would be more helpful, but line 6 is where the function definition ends, and so arguably is when the function is defined. You could have a "one a day" whole year calendar on the idiosyncrasies of PHP and have enough left over for a sequel. As others have also hinted, some basic debugging would confirm whether you are including the file more than once and also from where.
Make sure that your code uses include_once or require_once.

"Call to a member function .. on a non-object" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi, I am following this guide and copying exactly what is posted (except the author forgot some curly brackets, and I changed passwords etc). My problem is in the register.inc.php file.
Here is the following error I receive when a user tries to register
Call to a member function prepare() on a non-object in /home/ / /includes/register.inc.php on line 48
Line 48 of the file is
$stmt = $members_mysqli->prepare($prep_stmt);
Here is the entire register.inc.php file:
http://pastebin.com/YcQ7unb0 (It's not being properly formatted on this site)
$members_mysqli is probably a typo. It was never created. You use another variable named $mysqli. Maybe that's the one you meant to use. Check your include files and make sure you actually instantiated $members_mysqli.
The "call to member function on non-object" error is thrown when you try to use an uncreated/uninstantiated variable as an object.
For example:
// create an object
$blah = new Blah();
// call a function on it
$blah->doSomething();
// no error, because $blah exists. however, if my next line is:
$blue->doSomething();
// I'd get an error because $blue was never created

Accessing arrays through methods [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Why is it that in PHP 5.3.8:
$obj->foo()['bar']; // syntax error
$obj->foo()->['bar']; // valid
But in PHP 5.4.9 it's reverse:
$obj->foo()['bar']; // valid
$obj->foo()->['bar'] // syntax error
$obj->foo()['bar']; is valid in PHP >= 5.4.0
$obj->foo()->['bar'] is not valid in any version even if you add the required ;
So in versions before 5.4.0 you will get a parse error on the first line that will stop execution and not show the parse error on the next line.
In versions 5.4.0 and greater the first line works but you get a parse error on the second. So if you reverse them, you will always get the parse error for $obj->foo()->['bar'] in any version.
Example $obj->foo()->['bar'] was never valid, in any PHP version; see here.
Maybe you got it mistaken with syntax like $obj->foo()->{'bar'}; see here.
Example $obj->foo()['bar'] is valid from PHP >= 5.4.0; see here.
Support for
$obj->foo()['bar'];
came in PHP 5.4.0 as support for function array dereferencing was added only from that version.
This useful page explains it:
https://wiki.php.net/rfc/functionarraydereferencing
Your first example has never been valid.
$obj->foo()->['bar']; // is invalid in any PHP implementation
However with method chaining support: if $obj->foo() returns an object with a bar property this will work:
$obj->foo()->bar;

Categories