Jump to content

problems parsing class file


lvoTusk

Recommended Posts

OK, so my original problem was I was getting a class not found error after including a file that contains my class definition.
I have narrowed the problem down, so that if I give a full URL to the class' file, it DOES NOT let me use the class, whereas
if I give a relative path to the class' file it WILL let me use the file.

e.g
In my server structure (say in localhost/FOLDER1/
I have a file ClassA.php
and also index.php

if in index.php I do
[code]
include('ClassA.php');
$a = new A;
[/code]

This works fine, however, if in index.php I do
[code]
include('http:/localhost/FOLDER1/ClassA.php');
$a = new A;
[/code]
I get a "class ClassA not found" error.
BUT I have put an echo statement in my class' file, and in both cases the file is actually being included
as the specific echo is occurring.

any ideas ?

cheers
Link to comment
Share on other sites

use file system strings, not http:// urls.

Relative path's can also be used.

e.g. if your includes are in "/var/www/includes/" but your document root is "/var/www/docroot/" and you want to use an include file in your main index, you can use:

[code]<?php

include '../includes/ClassFile.php';

//etc.

?>[/code]

I prefer to use realpath() to get the absolute path (also to verify the path exists) before including however.
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.