Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 5th, 2005, 5:50 AM   #1
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
Can anyone see whats wrong with this code?

Ive started looking at php5. Looking good in theory!!
Stuck on first bit!

class.Demo.php
<?
class Demo
{
function sayHello($name)
{
print "Hello $name";
}//finction sayHello
}


?>



demoTest.php
<?

include '/php5/class.Demo.php';
$demo = new Demo();
$demo->sayHello(kapil);

?>



I have a feeling that include() cannot be used on classes??

Thanks in advance
k4pil is offline   Reply With Quote
Old Sep 5th, 2005, 6:45 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
What error message do you get?

Could the problem be caused by 'kapil' not being in double quotes?
Arevos is offline   Reply With Quote
Old Sep 5th, 2005, 7:23 AM   #3
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
Warning: main(): open_basedir restriction in effect. File(/php5/class.Demo.php) is not within the allowed path(s): (/home/kapi7150:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/kapi7150/public_html/php5/demoTest.php on line 3

Warning: main(/php5/class.Demo.php): failed to open stream: Operation not permitted in /home/kapi7150/public_html/php5/demoTest.php on line 3

Warning: main(): open_basedir restriction in effect. File(/php5/class.Demo.php) is not within the allowed path(s): (/home/kapi7150:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/kapi7150/public_html/php5/demoTest.php on line 3

Warning: main(/php5/class.Demo.php): failed to open stream: Operation not permitted in /home/kapi7150/public_html/php5/demoTest.php on line 3

Warning: main(): Failed opening '/php5/class.Demo.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kapi7150/public_html/php5/demoTest.php on line 3

Fatal error: Cannot instantiate non-existent class: demo in /home/kapi7150/public_html/php5/demoTest.php on line 4




NOT NICE
k4pil is offline   Reply With Quote
Old Sep 5th, 2005, 7:51 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I suppose the presence of error messages tends to farble with one's mind, when new to a language. They're pretty clear. You aren't allowed access to that file for some reason. If you did have access, there'd still be the problem Arevos mentions.

Is there any reason you're using includes and classes at the "Hello World" level? Personally, were I tutoring you, I'd bring you along a tad further, then introduce the include/require, then introduce classes.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 5th, 2005, 8:08 AM   #5
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
Farble...erm...

The reason im using include and classes is that im using an advanced book. I have already covered php4 and java, now having a look at php5, however, im crap at all really!

Need it for a project at uni.

Any reason why i don't have access??
k4pil is offline   Reply With Quote
Old Sep 5th, 2005, 8:32 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
Any reason why i don't have access??
Of course. If this is a "community system" it wouldn't even be unusual. In that case, check with your administrator. If it's a personal system, it's a setup issue. No way to answer "How do I fix it" without some nitty-gritty details.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 5th, 2005, 8:41 AM   #7
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Quote:
Originally Posted by Arevos
Could the problem be caused by 'kapil' not being in double quotes?
Although this is not good programming style PHP is very flexible with mistakes like this one. In PHP this would just issue a warning, and would assume if there was no variable named kapil to send a string "kapil" as the argument.
__________________

tempest is offline   Reply With Quote
Old Sep 5th, 2005, 9:01 AM   #8
k4pil
Programmer
 
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4 k4pil is on a distinguished road
Yeah, in the past i have used both double quotes and not. It works either way, but better programming practice
k4pil is offline   Reply With Quote
Old Sep 5th, 2005, 9:13 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Tempest is absolutely correct. I continue to be amazed at PHP's flexibility (I'm a newbie at PHP). If you solve your access problem, your code will work as written.
Attached Images
File Type: jpg kapil.jpg (14.5 KB, 52 views)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 5th, 2005, 9:27 AM   #10
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
add the path to the file in your php.ini
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC