![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
What error message do you get?
Could the problem be caused by 'kapil' not being in double quotes? |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
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?? |
|
|
|
|
|
#6 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() |
Quote:
__________________
|
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Aug 2005
Location: Leeds - UK
Posts: 69
Rep Power: 4
![]() |
Yeah, in the past i have used both double quotes and not. It works either way, but better programming practice
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
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 |
|
|
|
|
|
#10 |
|
Professional Programmer
|
add the path to the file in your php.ini
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|