On being PHPs bitch - OO programming

Status
Not open for further replies.

emp

New member
Jun 29, 2006
7,465
211
0
OK.. Stupid question

Why does this work just fine:

Code:
<?php
    class DBconnector{
    //vars
    var $userName;

    //constructor
    function DBconnector($user)
        {
        //assign the variables
        $this->userName = $user;
    function connectme()
        {
        //sets up a new connection to the database table
        //.............
        }
    }
    $connect = new DBconnector("userName");
    echo "Username is:".$connect->userName; 
 ?>
but not when I include it like this, using two files:

Code:
<?php
    include ('dbconnector.php');
     $connect = new DBconnector("userName");
    echo "Username is:".$connect->userName; 
?>
Anyone???

::emp::
 


PS: I actually get NO output after the creation of the instance.

::emp::
 
PPS: Solved it.

Kids, use require_once and all lowercase file names.

::emp::
 
For future reference, the only difference between require and include is in the way it handles failure; require_once and include_once shouldn't have made much difference either.

Further, there's no need to use all lower-case file names - as long as you match the case in the filename and the require/include.

So while what you suggest will work, I hereby amend your advice to:

Kids, require and include statements are case sensitive.
 
So... It depends on whether or not the filesystem is case-sensitive.
 
Funny thing is, my require and the filename were exactly the same.

DBconnector.php

Would not work until I changed both to

dbconnector.php

Maybe a server issue/config I do not know.

::emp::
 
Did you get an error from the include when using the mixed-case filename?
 
Nope.

Just would not do ANYTHING that followed afterwards.

::emp::
 
Status
Not open for further replies.