LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2005, 03:56 PM   #1
it-s
Member
 
Registered: Nov 2004
Location: Canada
Distribution: SUSE 10
Posts: 69

Rep: Reputation: 15
PHP include


Hi everyone,

I'm not sure if it's a right place to ask, but I have nowhere else to go to

I'm trying to build a website in PHP and want to have some usefull functions in a separate file, so later I could just reuse then by including.
But, there seems to be a problem here:

file: test.php
PHP Code:
<?php
function usefull_function1(){

echo
"Some text";

}
?>

file: index.php
PHP Code:
<?PHP
include('test.php');

usefull_function1();
?>
once executed index.php shows an error:
Fatal error: Call to undefined function usefull_function1() in index.php on line 4



I juct don't understand why??? In any other programing languages an 'include' like directive just takes a premade code from a specific file and inserts it AS IS
Does PHP operate otherwise???


Thank you all in advance.

it-s
 
Old 10-05-2005, 04:15 PM   #2
Linc
LQ Newbie
 
Registered: Oct 2005
Distribution: Slackware
Posts: 4

Rep: Reputation: 0
Re: PHP include

Quote:
Originally posted by it-s
Hi everyone,

I'm not sure if it's a right place to ask, but I have nowhere else to go to

I'm trying to build a website in PHP and want to have some usefull functions in a separate file, so later I could just reuse then by including.
But, there seems to be a problem here:

file: test.php
PHP Code:
<?php
function usefull_function1(){

echo
"Some text";

}
?>

file: index.php
PHP Code:
<?PHP
include('test.php');

usefull_function1();
?>
once executed index.php shows an error:
Fatal error: Call to undefined function usefull_function1() in index.php on line 4



I juct don't understand why??? In any other programing languages an 'include' like directive just takes a premade code from a specific file and inserts it AS IS
Does PHP operate otherwise???


Thank you all in advance.

it-s
Easy mistake, just put your path in the include statment..
include("/var/www/htdocs/somedirectory/test.php");
 
Old 10-05-2005, 04:19 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
syntax is incorrect:

http://us2.php.net/manual/en/function.include.php
http://us2.php.net/manual/en/function.require.php
 
Old 10-05-2005, 11:07 PM   #4
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 32
Quote:
Originally posted by michaelk
syntax is incorrect:
Actually, no, the syntax is perfectly fine. If you're refering to the parentheses, they're not required, but you can still use them. They're only an issue when returning a value from a call to include().

I tried copying and pasting the given code into a couple of files in the same directory, and it ran perfectly for me, so the problem isn't there. It's probably a problem with your include_path. It probably just doesn't contain the directory where test.php is located.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP include() not working kodon Slackware 13 08-10-2004 06:05 AM
php include msound Programming 2 06-24-2004 04:21 PM
php include files abrb220 Programming 2 10-27-2003 07:54 AM
PHP Path include ..:eMa:.. Programming 4 09-25-2003 01:59 AM
repetitive conditional include() in PHP linuxfond Programming 12 09-17-2003 03:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration