Page 1 of 2

CS install help

Posted: Sat Jan 22, 2011 03:01
by Erundil
I tried to install cardscape on localhost, i ran install.php succesfully, but i get an error:

Parse error: syntax error, unexpected T_FUNCTION in /var/www/cardscape/index.php on line 15

I'm using the latest revision

Apache settings:
Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny9 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.5

Re: CS install help

Posted: Sat Jan 22, 2011 20:06
by pennomi
Hrm... did you change card_definition.txt or config.php at all? That could be the source of the problem.

Another possibility could be depending on what version of cardscape you are running. Where did you download from? The only cardscape install I can vouch for is the one that comes directly from the bzr trunk checkout.

The last possibility that I can think of is that I possibly broke the install.php function as I was editing everything. I'd have to take a look at the files you are using to find that problem.

Could you .tar or .zip the directory you are using and email it to me at pennomi (a) wtactics (dot) org? This would be the easiest way for me to evaluate the problem.

Re: CS install help

Posted: Sun Jan 23, 2011 00:26
by Erundil
I did not change card_definition.txt nor install.php.
The cardscape version is the one downloaded from bzr checkout, done yesterday.

As i said i ran install.php succesfully

Re: CS install help

Posted: Sun Jan 23, 2011 20:40
by pennomi
I used the data you sent me to try to recreate the bug. The install worked perfectly, and I can view the index.php page.

Your error looks like your PHP version is reading the file "index.php" as containing syntax errors. The error message points to the first line of the action array.

Code: Select all

$action = array(
		/* CARD FUNCTIONS */
		'show_card' => function() { //Error directs to here
			$pagename = get_card_name($_GET["id"])." | ";
			echo $db['prefix'];
I'm not the PHP expert, but it's possible that you have an outdated version of PHP which does not support storing functions in an array. Perhaps the syntax was changed; I'm not sure.

What I would recommend is upgrading to the most recent version of PHP and retesting the install. I currently use version 5.5.3-1ubuntu9.3. Or, if you know PHP, you can rewrite the index.php file in a different way. If you can make the index file run on more versions of PHP, I'd gladly replace the one I'm currently using with that.

Please tell me if this suggestion works or not.

Re: CS install help

Posted: Sun Jan 23, 2011 22:06
by snowdrop
When configuring PHP you can tell it how strict it will be when reporting about errors. There are a couple of different modes around - some of them are very conservative and should not be used.

I don't think that that setting is the problem here, but it might be worth checking up in any case. Feel free to mail all the cardscape files you used to me as well, and I'll see if I can reproduce your error. The fact that pennomi failed to do so does however indicate that the code isn't the issue... something else is... question is what. = P

(Btw: I'll email you in the days to come about italian translations if you'd be interested in being on the italian team?)

Re: CS install help

Posted: Mon Jan 24, 2011 01:15
by Erundil
I have an older version : 5.2.x.
(I'm interested in being in the italian team)

Re: CS install help

Posted: Mon Jan 24, 2011 15:22
by pennomi
Erundil wrote:I have an older version : 5.2.x.
It might be worth it to recode the index.php file to run on more versions of PHP so that it is more universal. Basically the theory behind the index file now is that there is an array built of display functions. Based on what the $_GET arguments are for the page, it calls the appropriate function from the array.

This line of code actually performs the action:

Code: Select all

$actions[$_GET['act']];
Probably, your version of PHP will work if we use a large "select-case" construct that just executes the actions instead of calling them from an array.

Re: CS install help

Posted: Mon Jan 24, 2011 18:31
by Knitter
Instead of storing a wrapper function that just call another onel, you could just store the function name and use PHP ability to call functions from strings. Pass the parameters using the variable arguments technique or don't pass any parameters and just let the called function get what she needs.

I believe it would be more inline with the usual way of doing things, though I don't really like most of the usual ways :D, but if storing the function is causing the problem it can be easily solve. And I really don't see any improvements, either in code readability or performance, or any other thing, in storing a bunch of functions inside an array.

Edit:

Better yet, remove the array completely and use the parameter passed in the URL to access the function you need, properly protected.

Re: CS install help

Posted: Mon Jan 24, 2011 21:10
by pennomi
Knitter wrote: Better yet, remove the array completely and use the parameter passed in the URL to access the function you need, properly protected.
I'm all for doing it the best way, whichever way that is. However, as far as code organization is concerned, I'll let Ravenchild (foodoo on IRC) call the shots on that one, since he knows a lot better than I do about structuring code appropriately in PHP. He's already corrected me on a few things that have been extremely helpful in the long run.

Also, if someone else would like to recode the index.php page, that would be best, since I am currently occupied with coding the remaining essential features. It'll be easy work, so are there any volunteers?

Re: CS install help

Posted: Tue Jan 25, 2011 14:31
by Ravenchild
Knitter wrote:Instead of storing a wrapper function that just call another onel, you could just store the function name and use PHP ability to call functions from strings. Pass the parameters using the variable arguments technique or don't pass any parameters and just let the called function get what she needs.
hm. Sounds rather dirty to me.
I believe it would be more inline with the usual way of doing things, though I don't really like most of the usual ways :D, but if storing the function is causing the problem it can be easily solve. And I really don't see any improvements, either in code readability or performance, or any other thing, in storing a bunch of functions inside an array.
This is far more readable than switch-statements. I understand that is is desirable to support as many PHP versions as possible. But functional programming (i.e. using functions as values) is such a powerful concept that I wouldn't like to drop it.
Better yet, remove the array completely and use the parameter passed in the URL to access the function you need, properly protected.
And how would this protection look like? You could use a switch-statement but I don't consider that a cleaner way than the array. Besides functions have the advantage that I can call them anytime from anywhere and even multiple times. And it is possible to execute several actions on a HTTP request. So you can create a link that will lead you to your profile overview and an overview of the latest changes.