d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php Parse Error...
12Next
Add Reply New Topic New Poll
Member
Posts: 85
Joined: Feb 14 2009
Gold: 0.01
Jul 16 2012 07:31pm
Code
<?php

Class cardImage{
   var $cardImg = imagecreatetruecolor(50, 80);//<-- error line
   
}

?>

with that code, I'm getting
Quote
Parse error: syntax error, unexpected '(', expecting ')' in example.php on line 4


and I have no idea why :(

This post was edited by gtackle62 on Jul 16 2012 07:32pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 16 2012 07:55pm
afaik you can't use "var" as a member variable. try changing that to private/public/protected

otherwise stick that in your constructor

my php knowledge is extremely limited though.

This post was edited by carteblanche on Jul 16 2012 07:55pm
Member
Posts: 85
Joined: Feb 14 2009
Gold: 0.01
Jul 16 2012 07:58pm
Quote (carteblanche @ Jul 16 2012 07:55pm)
afaik you can't use "var" as a member variable. try changing that to private/public/protected

otherwise stick that in your constructor

my php knowledge is extremely limited though.


already tried private/public/protected, same result
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 16 2012 07:59pm
is Class supposed to be capitalized? i think php is lowercase, no?

/edit im looking at this
http://php.net/manual/en/language.oop5.basic.php

This post was edited by carteblanche on Jul 16 2012 08:00pm
Member
Posts: 85
Joined: Feb 14 2009
Gold: 0.01
Jul 16 2012 08:03pm
Quote (carteblanche @ Jul 16 2012 07:59pm)
is Class supposed to be capitalized? i think php is lowercase, no?

/edit im looking at this
http://php.net/manual/en/language.oop5.basic.php


made it lowercase and it didn't change, I've also made classes w/ it uppercase before, I don't think it matters.

also used a function_exists() on the function name, returned true...

This post was edited by gtackle62 on Jul 16 2012 08:04pm
Member
Posts: 6,522
Joined: Jun 5 2008
Gold: 0.00
Jul 16 2012 08:21pm
Quote (gtackle62 @ Jul 16 2012 09:03pm)
made it lowercase and it didn't change, I've also made classes w/ it uppercase before, I don't think it matters.

also used a function_exists() on the function name, returned true...


for some odd reason you can't do that

I guess you have to do something like this

Code
<?php


class image {
function imagecreate() {
 $img = imagecreatetruecolor(50,80);
}
 
}
?>
Member
Posts: 85
Joined: Feb 14 2009
Gold: 0.01
Jul 16 2012 08:23pm
Quote (DeadShell @ Jul 16 2012 08:21pm)
for some odd reason you can't do that

I guess you have to do something like this

Code
<?php


class image {
function imagecreate() {
 $img = imagecreatetruecolor(50,80);
}
 
}
?>


Figured I might have to :/ thought there might be a workaround or something though, guess I'll just have to do it in the constructor or something similar, thanks.
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Jul 17 2012 05:14am
Quote (gtackle62 @ 17 Jul 2012 04:23)
Figured I might have to :/ thought there might be a workaround or something though, guess I'll just have to do it in the constructor or something similar, thanks.


Sure, why don't you want to?
http://codepad.viper-7.com/0RBGy7

Or you could just skip the whole class part. Don't use it if you don't need it.
Member
Posts: 6,522
Joined: Jun 5 2008
Gold: 0.00
Jul 17 2012 10:31am
Quote (eagl3s1ght @ Jul 17 2012 06:14am)
Sure, why don't you want to?
http://codepad.viper-7.com/0RBGy7

Or you could just skip the whole class part. Don't use it if you don't need it.


What's the reason that you can't define a variable without putting it inside a function, I'm kind of curious now?
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Jul 17 2012 12:33pm
Quote (DeadShell @ 17 Jul 2012 18:31)
What's the reason that you can't define a variable without putting it inside a function, I'm kind of curious now?

It's not so much about the defining of a variable as it is calling another function.

Quote
http://stackoverflow.com/questions/6486660/unexpected-t-variable-expecting-t-function
This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.


This post was edited by eagl3s1ght on Jul 17 2012 12:33pm
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll