Login   Register  
PHP Classes
elePHPant
Icontem

const error under php4

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PDO for PHP 4  >  All threads  >  const error under php4  >  (Un) Subscribe thread alerts  
Subject:const error under php4
Summary:Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCT
Messages:8
Author:Lukasz
Date:2006-02-04 11:16:07
Update:2009-12-02 22:43:16
 

  1. const error under php4   Reply  
Picture of Lukasz
Lukasz
2006-02-04 11:16:07
What should I do with lines:
const FETCH_ASSOC = PDO_FETCH_ASSOC;
...

to make it work?

  2. Re: const error under php4   Reply  
Picture of Andrea Giammarchi
Andrea Giammarchi
2006-02-06 08:56:39 - In reply to message 1 from Lukasz
all constant are defined in the same way ... try with

<?php
require 'PDO.class.php';
echo PDO::FETCH_ASSOC.'<br />';
?>

It works for me, then problem is in your script, post it or I cant help you :-(

  3. Re: const error under php4   Reply  
Picture of Lukasz
Lukasz
2006-02-06 12:16:42 - In reply to message 2 from Andrea Giammarchi
I was talking about error message when I'm opening PDO_Example_Script.php

Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in c:\wamp\www\pdo\PDO\PDO.class.php on line 88

http://icdesign.pl/tools/pdo/PDO_Example_Script.php
and here is phpinfo
http://icdesign.pl/tools/pdo/info.php

the line 88 is:
const FETCH_ASSOC = PDO_FETCH_ASSOC;

the problem is with all lines declaring const

  4. Re: const error under php4   Reply  
Picture of Andrea Giammarchi
Andrea Giammarchi
2006-02-06 13:44:45 - In reply to message 3 from Lukasz
Oooops, sorry guys, you're right !

In PHP4 is not possible to define an internal constant, I totally foget it !!! ( wow, I need less beer !!! :D )

you should replace that piece of code (and then code in the else too) with this one:

function FETCH_ASSOC(){return PDO_FETCH_ASSOC;}
function FETCH_NUM(){return PDO_FETCH_NUM;}
function FETCH_BOTH(){return PDO_FETCH_BOTH;}
function FETCH_OBJ(){return PDO_FETCH_OBJ;}
function FETCH_LAZY(){return PDO_FETCH_LAZY;}
function FETCH_BOUND(){return PDO_FETCH_BOUND;}
function ATTR_SERVER_VERSION(){return PDO_ATTR_SERVER_VERSION;}
function ATTR_CLIENT_VERSION(){return PDO_ATTR_CLIENT_VERSION;}
function ATTR_SERVER_INFO(){return PDO_ATTR_SERVER_INFO;}
function ATTR_PERSISTENT(){return PDO_ATTR_PERSISTENT;}


and use always old way to call PDO constant, for example: PDO_FETCH_NUM and not PDO::FETCH_NUM() because on PHP upgrade your script will don't work :-(


another trick for this solution should include a file like this one:

<?php
if(defined('PDO::FETCH_NUM')) {
eval("define('PDO_ATTR_SERVER_VERSION', PDO::ATTR_SERVER_VERSION);");
eval("define('PDO_ATTR_CLIENT_VERSION', PDO::ATTR_CLIENT_VERSION);");
eval("define('PDO_ATTR_SERVER_INFO', PDO::ATTR_SERVER_INFO);");
eval("define('PDO_ATTR_PERSISTENT', PDO::ATTR_PERSISTENT);");
eval("define('PDO_FETCH_ASSOC', PDO::FETCH_ASSOC);");
eval("define('PDO_FETCH_NUM', PDO::FETCH_NUM);");
eval("define('PDO_FETCH_BOTH', PDO::FETCH_BOTH);");
eval("define('PDO_FETCH_OBJ', PDO::FETCH_OBJ);");
eval("define('PDO_FETCH_LAZY', PDO::FETCH_LAZY);");
eval("define('PDO_FETCH_BOUND', PDO::FETCH_BOUND);");
}
?>

that should work in PHP4 as in PHP5 or 5.1 without problems :-)

  5. Re: const error under php4   Reply  
Picture of Lukasz
Lukasz
2006-02-06 14:41:56 - In reply to message 4 from Andrea Giammarchi
Ok, the first advised fixed the problem but the second didn't ;)

I've included file - require('PDO/names.inc.php');
<?php
if(defined('PDO::FETCH_NUM')) {
eval("define('PDO_ATTR_SERVER_VERSION', PDO::ATTR_SERVER_VERSION);");
eval("define('PDO_ATTR_CLIENT_VERSION', PDO::ATTR_CLIENT_VERSION);");
eval("define('PDO_ATTR_SERVER_INFO', PDO::ATTR_SERVER_INFO);");
eval("define('PDO_ATTR_PERSISTENT', PDO::ATTR_PERSISTENT);");
eval("define('PDO_FETCH_ASSOC', PDO::FETCH_ASSOC);");
eval("define('PDO_FETCH_NUM', PDO::FETCH_NUM);");
eval("define('PDO_FETCH_BOTH', PDO::FETCH_BOTH);");
eval("define('PDO_FETCH_OBJ', PDO::FETCH_OBJ);");
eval("define('PDO_FETCH_LAZY', PDO::FETCH_LAZY);");
eval("define('PDO_FETCH_BOUND', PDO::FETCH_BOUND);");
}
?>

in example script but new error apeared
Parse error: parse error, expecting `','' or `';'' in c:\wamp\www\pdo\PDO\PDOStatement_mysql.class.php on line 39

the line is:
var $__fetchmode = PDO::FETCH_BOTH;

should I put it right this
var $__fetchmode = PDO_FETCH_BOTH;

Or do you have another fix :)?

  6. Re: const error under php4   Reply  
Picture of Andrea Giammarchi
Andrea Giammarchi
2006-02-06 15:41:08 - In reply to message 5 from Lukasz
uhm ... no other fix, just check other PDOStatements or other PDO dedicated db classes, maybe there are some static vars that cannot run on PHP4 , bye and thank you for this report :-)

  7. Re: const error under php4   Reply  
Picture of Michael Will
Michael Will
2009-08-05 23:20:34 - In reply to message 6 from Andrea Giammarchi
Is there an older version of 'PDO for PHP4' that actually worked on PHP4?

All the class constant definitions are PHP5 stuff and don't make sense on php4. And for PHP5 we don't need it in the first place, there it works just out of the box without these classes, at least when I last checked on a redhat 5 system.

Michael.

  8. Re: const error under php4   Reply  
Picture of T S
T S
2009-12-02 22:43:16 - In reply to message 7 from Michael Will
That's a pretty poor response Andrea - Bye seriously? Is there a version that actually works with PHP4? That's the whole point of this after all.