Jump to content

[SOLVED] Further problem with require()


pk-uk

Recommended Posts

This appears to work:

$ipath = get_include_path() ;
echo "The include path is: $ipath      "  ;


$filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;
if (file_exists($filename)) {
    echo "The file $filename exists <br />";
} else {
    echo "The file $filename does not exist <br />";
}

require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;

$smarty = new Smarty;

$smarty->compile_check = true;
$smarty->debugging = true;

$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");

 

However, this doesn't (and I want it to!)

$ipath = get_include_path() ;
echo "The include path is: $ipath<br />"  ;


$filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/inc/php.inc.php' ;
if (file_exists($filename)) {
    echo "The file $filename exists<br />";
} else {
    echo "The file $filename does not exist<br />";
}

require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/inc/php.inc.php' ;

// $smarty = new Smarty;

$smarty->compile_check = true;
$smarty->debugging = true;

$smarty->assign("Name","Fred Irving Johnathan Bradley Peppergill");

 

It results in a failure on the last line: Fatal error: Call to undefined method stdClass::assign() in /usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/demo/index.php on line 21

 

The included file contains:

$site_root = $SERVER["HTTP_HOST"] . "/" ;
echo "    site root: $site_root<br />" ;

define ('SMARTY_DIR', '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/');
echo 'Smarty Dir: ' . SMARTY_DIR . '<br />' ;

$filename =  SMARTY_DIR . 'Smarty.class.php' ;
if (file_exists($filename)) {
     echo "  The file $filename exists<br />";
 require (SMARTY_DIR . 'Smarty.class.php');
 $Smarty = new Smarty ;
} else {
     echo "  The file $filename does not exist<br />";
}

 

and the resultant trace displays:

The include path is: .:

The file /usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/inc/php.inc.php exists

site root: /

Smarty Dir: /usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/

The file /usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php exists

 

 

Again, any help gratefully appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/85594-solved-further-problem-with-require/
Share on other sites

require() is a function, it needs parenthesis

 

change

require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;

to

require ('/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php');

 

require() is a function, it needs parenthesis

 

change

require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;

to

require ('/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php');

 

 

require is not a function, but a language construct. And no, it does not need parenthesis around its arguments.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.