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 7 years ago.
Improve this question
I have two PHP scripts, dispatcher.php and processor.php (there are more, but I've commented the others out because they're not necessary at the moment).
I get the following error:
Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /----home directory-----/classes/processor.php on line 12
Here's the code for processor.php:
class Processor{
protected $player;
protected $name;
protected $id;
function __construct(){
}
function loadvars($request){
$this->loadvar($this->name, $request, "name");
}
private function loadvar($target, $request, $name){
if(isset($request[$name])){
$target = $request[$name];
}
else{
$target = "";
}
}
}
this is the code for dispatcher.php:
require('classes/processor.php');
$test = new Processor();
$test->loadvars($_GET);
I don't see why this error occurs?
I'm coding using Sublime on Windows, if that matters.
Fixed it!
Try retyping the file if you have weird parse errors. I copied the code back from StackOverflow (where I typed it above) and it worked. Guess some unparseable character got into the file somewhere.
Related
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 6 years ago.
Improve this question
I'm getting this error and I can't make head or tail of it.
The exact error message is:
function kdrusha_theme_create_page() {
require_once(get_template_directory().= '/inc/pages/kdrusha-settings.php');
}
add_menu_page("KD Rusha Options", 'KD Rusha', 'manage_options', 'kdrusha-options', 'kdrusha_theme_create_page','',99);
The problem is that you're using .=.
something .= something_else
is shorthand for
something = something . something_else
But your something is a function call, and it generally doesn't make sense to assign to a function call (the exception is when it returns a reference).
You should just use ., which concatenates its parameters and returns the result without assigning it anywhere.
require_once(get_template_directory() . '/inc/pages/kdrusha-settings.php');
You need to put your function return in some variable:
function kdrusha_theme_create_page() {
$template = get_template_directory();
require_once($template.'/inc/pages/kdrusha-settings.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 7 years ago.
Improve this question
Since installing Mac OSX El Capitain, I am getting a parse error. The code works fine on the server, but on my development workstation, I get this error consistently.
Parse error: parse error in /Library/WebServer/Documents/website/includes/config.php on line 4
// Calling code snippet:
include("includes/navbar.php");
require_once("includes/config.php");
$servername = DBHOST;
$username = DBUSER;
$password = DBPASS;
$database = DBNAME;
config.php file:
<?php
/* Config File for Common Values */
define ("DBHOST", “127.0.0.1:3306”); <--- This is line 4
define ("DBUSER", “userid”);
define ("DBPASS", “password”);
define ("DBNAME", “database”);
?>
You're using smart quotes (“ and ”) where you should have straight quotes ("). Replace the smart quotes with straight quotes. For example, change
“127.0.0.1:3306”
to
"127.0.0.1:3306"
Do the same with each of the other define() statements.
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 7 years ago.
Improve this question
I am trying to make a for loop that will give me the integers 1 to 1000. i have gotten this error message and cant find out what i did wrong. i looked threw people who got the same message but could not find a helpful answer that fit my need. the full error message was
Parse error: syntax error, unexpected 'numberToTest' (T_STRING), expecting function (T_FUNCTION) in C:\xampp\htdocs\prime2\primeNumberFinder.php on line 15
here is the code:
<?php
class primeNumber{
function numberToTest(){
for($i=0; $i<1000; ++$i){
echo "$i<br>";
}
}
numberToTest();
}
?>
thanks!
You need to close the class with a } before trying to call its methods
You also need to call the class method correctly, as a method of an instantiated class
<?php
class primeNumber{
public function numberToTest(){
for($i=0; $i<1000; ++$i){
echo "$i<br>";
}
}
}
// Create an instance of the class as $x
$x = new primeNumber();
// Call the numberToTest() method of your instantiated class
$x->numberToTest();
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
I am trying to write a program using Call By Reference to calculate the area but I am getting a Parse Error :-
Parse error: syntax error, unexpected 'ar' (T_STRING) in C:\xampp\htdocs\workspace.php on line 7
Now I, cannot think why it is happening?
<?php
function perimeter(&$l,&$b,&$result)
{
$result=2*($l+$b);
}
funtction ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}
$result=1;
$length=$_GET['length'];
$breadth=$_GET['breadth'];
echo "<h1><center>Area And Perimeter Calculator Using Call By Reference</h1></center>";
$result = perimeter($length,$breadth,$result);
echo "<br />The Perimeter Of The Rectangle Is <strong>$result</strong>";
$result= ar($length,$breadth,$result);
echo "<br /><br />The Area Of The Rectangle Is = <strong>$result</strong>";
?>
You misspelled function:
funtction ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}
should be
function ar(&$le,&$br,&$result1)
{
$result1=$le*$br;
}
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 9 years ago.
Improve this question
I think this might be a simple issue of variable scope, but I'm stumped as to where the issue lies. Given the following lines of code
class mysqlaccess {
private $creds;
private $error;
protected $con;
public $dir;
public function __construct () {
$this->$dir = "../../../../../private/mysqlinfo.ini";
}
}
when I try to reference this public variable from another file like so
include_once ('mysqlaccess.php');
$s = new mysqlaccess();
echo $s->dir;
I get the following errors
undefined variable dir
and
cannot access empty property
my understanding was that this was how the construct function was supposed to work. Am I missing something?
Typo here -
$this->$dir = "..
^
should be
$this->dir = "..
You need: $this->dir instead of $this->$dir.
Look here as example.
You have to use this(without $):
$this->dir