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
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 not a function, but a language construct. And no, it does not need parenthesis around its arguments.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.