session_start and __autoload()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giacomo

    session_start and __autoload()

    Hi all.
    I just don't understand the behaviour of this: i have a few-webpages
    application in which I have these two files (and all the others)

    classes/class.User.php
    include/stdinclude.php

    the code of stdinclude.php is the following:

    <CODE>
    ....
    session_start() ;

    function __autoload( $classname ) {
    require_once "../classes/class.$class_na me.php";
    }
    ....
    </CODE>

    I was getting the require_once-fatal-error becouse the script couldn't
    find "../classes/class.User.php" , and I tried to understand where the
    include path pointed to: so i dumped the stacktrace and that's what
    was in:

    (please read the first entry even if it's long)
    <BACKTRACE>
    [0]=>
    array(2) {
    ["function"]=>
    string(10) "__autoload "
    ["args"]=>
    array(1) {
    [0]=>
    &string(4) "User"
    }
    }
    [1]=>
    array(4) {
    ["file"]=>
    string(72) "C:\foo\include \stdinclude.php "
    ["line"]=>
    int(3)
    ["function"]=>
    string(13) "session_st art"
    ["args"]=>
    array(0) {
    }
    }
    [2]=>
    array(4) {
    ["file"]=>
    string(68) "C:\foo\include \header.php"
    ["line"]=>
    int(3)
    ["args"]=>
    array(1) {
    [0]=>
    string(72) "C:\foo\include \stdinclude.php "
    }
    ["function"]=>
    string(12) "require_on ce"
    }
    [3]=>
    array(4) {
    ["file"]=>
    string(59) "C:\foo\index.p hp"
    ["line"]=>
    int(1)
    ["args"]=>
    array(1) {
    [0]=>
    string(68) "C:\foo\include \header.php"
    }
    ["function"]=>
    string(7) "include"
    }
    }
    </BACKTRACE>

    in the $_SESSION variable i have an object of type User, and the
    session_start() call tries to load the class User by means of
    __autoload function, but it is located in nowhere, so i cannot use any
    relative path in the require_once ..

    this never happends to me before; is this a correct php behaviour ?
    should I fix with an absolute path ?

    tnx, bye
    M

  • Hendri Kurniawan

    #2
    Re: session_start and __autoload()

    Giacomo wrote:
    Hi all.
    I just don't understand the behaviour of this: i have a few-webpages
    application in which I have these two files (and all the others)
    >
    classes/class.User.php
    include/stdinclude.php
    >
    the code of stdinclude.php is the following:
    >
    <CODE>
    ...
    session_start() ;
    >
    function __autoload( $classname ) {
    require_once "../classes/class.$class_na me.php";
    }
    ...
    </CODE>
    >
    I was getting the require_once-fatal-error becouse the script couldn't
    find "../classes/class.User.php" , and I tried to understand where the
    include path pointed to: so i dumped the stacktrace and that's what
    was in:
    >
    this never happends to me before; is this a correct php behaviour ?
    should I fix with an absolute path ?
    >
    tnx, bye
    M
    >
    Try using dirname(__FILE_ _).
    So: require_once dirname(__FILE_ _)."/../classes/class.$class_na me.php";

    Hendri

    Comment

    • Martin Mandl - m2m tech support

      #3
      Re: session_start and __autoload()

      On Mar 8, 4:46 am, Hendri Kurniawan <ask...@email.c omwrote:
      Giacomo wrote:
      Hi all.
      I just don't understand the behaviour of this: i have a few-webpages
      application in which I have these two files (and all the others)
      >
      classes/class.User.php
      include/stdinclude.php
      >
      the code of stdinclude.php is the following:
      >
      <CODE>
      ...
      session_start() ;
      >
      function __autoload( $classname ) {
      require_once "../classes/class.$class_na me.php";
      }
      ...
      </CODE>
      >
      I was getting the require_once-fatal-error becouse the script couldn't
      find "../classes/class.User.php" , and I tried to understand where the
      include path pointed to: so i dumped the stacktrace and that's what
      was in:
      >
      this never happends to me before; is this a correct php behaviour ?
      should I fix with an absolute path ?
      >
      tnx, bye
      M
      >
      Try using dirname(__FILE_ _).
      So: require_once dirname(__FILE_ _)."/../classes/class.$class_na me.php";
      >
      Hendri
      Dear Giacomo,

      the path for require_once() is relative to the initial file, e.g.

      1) dummy.php -include('includ e/stdinclude.php' );
      2) include/stdinclude.php -require_once('c lasses/
      class.User.php' ); // path is relative to dummy
      3) classes/class.User.php

      I hope that helped
      Martin


      ------------------------------------------------
      online accounting on bash bases
      Online Einnahmen-Ausgaben-Rechnung

      ------------------------------------------------
      m2m server software gmbh


      Comment

      • Giacomo

        #4
        Re: session_start and __autoload()

        On 8 Mar, 10:21, "Martin Mandl - m2m tech support"
        <martin.ma...@g mail.comwrote:
        On Mar 8, 4:46 am, Hendri Kurniawan <ask...@email.c omwrote:
        >
        >
        >
        Giacomo wrote:
        Hi all.
        I just don't understand the behaviour of this: i have a few-webpages
        application in which I have these two files (and all the others)
        >
        classes/class.User.php
        include/stdinclude.php
        >
        the code of stdinclude.php is the following:
        >
        <CODE>
        ...
        session_start() ;
        >
        function __autoload( $classname ) {
        require_once "../classes/class.$class_na me.php";
        }
        ...
        </CODE>
        >
        I was getting the require_once-fatal-error becouse the script couldn't
        find "../classes/class.User.php" , and I tried to understand where the
        include path pointed to: so i dumped the stacktrace and that's what
        was in:
        >
        this never happends to me before; is this a correct php behaviour ?
        should I fix with an absolute path ?
        >
        tnx, bye
        M
        >
        Try using dirname(__FILE_ _).
        So: require_once dirname(__FILE_ _)."/../classes/class.$class_na me.php";
        >
        Hendri
        >
        Dear Giacomo,
        >
        the path for require_once() is relative to the initial file, e.g.
        >
        1) dummy.php -include('includ e/stdinclude.php' );
        2) include/stdinclude.php -require_once('c lasses/
        class.User.php' ); // path is relative to dummy
        3) classes/class.User.php
        >
        I hope that helped
        Martin
        >
        Thanks everybody.. i was confused by the fact the if i do this it
        works:

        1) dummy.php -include('includ e/stdinclude.php' );
        2) include/stdinclude.php - require_once('b ar.php');
        3) include/bar.php

        ... and of course by the fact that it was 2.00 am o'clock ;)

        thanks
        bye
        M'

        Comment

        Working...