www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help with including classes in php

  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Help with including classes in php

    i've ben doing reasearch and I can't figure out why this doesn't work. here is the code

    index.php
    PHP Code:
    <?php 
    require_once 'http://' $_SERVER["HTTP_HOST"] . '/new_tech/test.php';
    $c = new C;
    ?>
    test.php
    PHP Code:
    <?php 
    class {
        const 
    test "Hello";
    }
    echo 
    'test';
    ?>
    the out put is test and then 'Fatal error: Class 'C' not found in C:\Users\Owner\Dropbox\test_server\old\index.php on line 4'
    does anyone know why this isn't working?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,528
    Because you are including it via http, which means all you get is whatever it outputs when the web server processes it as a PHP file. You should include it via a local filesystem path, not via HTTP.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,528
    PHP Code:
    require_once $_SERVER['DOCUMENT_ROOT'].'/new_tech/test.php'
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles