Cannot instantiate non-existent class

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

    #1

    Cannot instantiate non-existent class

    I'm having problems with include. I wrote a small example which shows
    what's going on...

    I should say that the problems started after I moved to a shared
    server. All was working fine in my local server...


    file test.php
    ---------------------------------------------------
    <?php

    echo '<html>';
    echo '<head>';
    echo '</head>';
    echo '<body>';

    echo "including inc.php<br>";

    include("http://my_site/inc.php");

    echo "inc was included<br>";

    $clsIncClass = new ClsIncClass;

    echo '</body>';
    echo '</html>';

    ?>

    file inc.php
    ---------------------------------------------------
    class ClsIncClass {
    function ClsIncClass() {
    echo "ClsIncClas s constructor<br> ";
    }
    }


    result in browser:

    including inc.php
    class ClsIncClass { function ClsIncClass() { echo "ClsIncClas s
    constructor
    "; } }inc was included

    Fatal error: Cannot instantiate non-existent class: clsincclass in
    /home/ke000067/public_html/test1.php on line 21

    Note that it seems that inc.php was included as if it were a text file,
    but as you can imagine, it's not my intention...


    So, i decided to change

    include("http://IP_of_my_site/inc.php");

    to

    include($_SERVE R['DOCUMENT_ROOT']."/my_site/inc.php");

    but the result was

    including inc.php

    including inc.php

    Warning: main(/opt/apache/htdocs/~ke000067/public_html/inc.php): failed
    to open stream: No such file or directory in
    /home/ke000067/public_html/test1.php on line 15

    Warning: main(/opt/apache/htdocs/~ke000067/public_html/inc.php): failed
    to open stream: No such file or directory in
    /home/ke000067/public_html/test1.php on line 15

    Warning: main(): Failed opening
    '/opt/apache/htdocs/~ke000067/public_html/inc.php' for inclusion
    (include_path=' .:/opt/apache/lib/php') in
    /home/ke000067/public_html/test1.php on line 15
    inc was included

    Fatal error: Cannot instantiate non-existent class: clsincclass in
    /home/ke000067/public_html/test1.php on line 23


    Anyone could give me some hints?

    regards - jm

  • julian_m

    #2
    Re: Cannot instantiate non-existent class

    just to add another detail, executing phpinfo I get

    open_basedir =
    /opt/apache/htdocs:/tmp:/opt/ferozo/suspended.page:/opt/ferozo/etc/suspension

    executing
    echo "Server Path: ". $_SERVER['DOCUMENT_ROOT']."<br>";
    I get
    Server Path: /opt/apache/htdocs

    regards - jm

    Comment

    • Iván Sánchez Ortega

      #3
      Re: Cannot instantiate non-existent class

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      julian_m wrote:
      [color=blue]
      > include("http://IP_of_my_site/inc.php");
      >
      > to
      >
      > include($_SERVE R['DOCUMENT_ROOT']."/my_site/inc.php");[/color]
      [...][color=blue]
      > Anyone could give me some hints?[/color]

      Use relative paths. And never ever include anything starting with http://
      (or https://, or ftp://, for that matter).

      include('inc.ph p');
      include('./inc.php');

      - --
      - ----------------------------------
      Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

      Fórmula del condón: No-metil-lacolina-oxi-metil-metila-con-gomina.

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.2 (GNU/Linux)

      iD8DBQFEBLmz3jc Q2mg3Pc8RAu6lAJ 96DeWHAs3GDjOqy 7XFfgGnVQZpFACg gDf0
      K64neZtGRl5h6vP ovRKi/JA=
      =R0rM
      -----END PGP SIGNATURE-----

      Comment

      • julian_m

        #4
        Re: Cannot instantiate non-existent class


        Iván Sánchez Ortega wrote:[color=blue]
        > julian_m wrote:
        >[color=green]
        > > include("http://IP_of_my_site/inc.php");
        > >
        > > to
        > >
        > > include($_SERVE R['DOCUMENT_ROOT']."/my_site/inc.php");[/color]
        > [...][color=green]
        > > Anyone could give me some hints?[/color]
        >
        > Use relative paths. And never ever include anything starting with http://
        > (or https://, or ftp://, for that matter).
        >
        > include('inc.ph p');
        > include('./inc.php');[/color]

        Yes, I've read previous answer from yourself (googling a little bit) in
        which you said exactly the same.

        The problem is that i can't include the file in the shared server, even
        though I can do in my local server

        the following line

        include(inc.php );

        works as expected in my local server, but fires up this in the shared
        server

        Warning: main(): open_basedir restriction in effect. File(/inc.php) is
        not within the allowed path(s):
        (/opt/apache/htdocs:/tmp:/opt/ferozo/suspended.page:/opt/ferozo/etc/suspension)
        in /home/ke000067/public_html/test1.php on line 17

        Warning: main(/inc.php): failed to open stream: Operation not permitted
        in /home/ke000067/public_html/test1.php on line 17

        Is there any workaround to this, or I just simply can't include *any*
        file?
        Note that I've not access to php.ini...

        sdos - jm

        Comment

        • kay

          #5
          Re: Cannot instantiate non-existent class

          try first with the most simple - try including a file that is placed in
          the same directory as the script, forget about classes etc. if u cant
          include it - contact your ISP and ask them what to do :-)

          Comment

          • julian_m

            #6
            Re: Cannot instantiate non-existent class


            kay wrote:[color=blue]
            > try first with the most simple - try including a file that is placed in
            > the same directory as the script[/color]

            That's what I tried hundred times...
            [color=blue]
            > forget about classes etc. if u cant
            > include it - contact your ISP and ask them what to do :-)[/color]

            They said:
            'access to your file with absolute path:
            "www.yoursite.c om/your_file.php" '

            It's really strange
            isnt it?

            sdos - jm

            Comment

            • Jerry Stuckle

              #7
              Re: Cannot instantiate non-existent class

              julian_m wrote:[color=blue]
              > kay wrote:
              >[color=green]
              >>try first with the most simple - try including a file that is placed in
              >>the same directory as the script[/color]
              >
              >
              > That's what I tried hundred times...
              >
              >[color=green]
              >>forget about classes etc. if u cant
              >>include it - contact your ISP and ask them what to do :-)[/color]
              >
              >
              > They said:
              > 'access to your file with absolute path:
              > "www.yoursite.c om/your_file.php" '
              >
              > It's really strange
              > isnt it?
              >
              > sdos - jm
              >[/color]

              Julian,

              The problem is - when you access it through http, all you get is the
              HTML (if any) generated by the script. This is how it should be -
              otherwise anyone would be able to access your source code!

              IIWY I would go back to the host and get a better answer. If you can't
              get a better answer than that, change hosts!

              include('inc.ph p') is a very basic statement, and used *very* heavily in
              PHP. If it doesn't work on your host, and they can't fix it, its time
              to get a new host!

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • julian_m

                #8
                Re: Cannot instantiate non-existent class


                Jerry Stuckle wrote:
                [color=blue]
                > Julian,
                >
                > The problem is - when you access it through http, all you get is the
                > HTML (if any) generated by the script. This is how it should be -
                > otherwise anyone would be able to access your source code![/color]

                Right, I undestand...
                [color=blue]
                > IIWY I would go back to the host and get a better answer. If you can't
                > get a better answer than that, change hosts!
                >
                > include('inc.ph p') is a very basic statement, and used *very* heavily in
                > PHP. If it doesn't work on your host, and they can't fix it, its time
                > to get a new host![/color]

                Fine, that's what I was thinking right now. Thanks all you for the
                help.

                regads - jm

                Comment

                • Steve

                  #9
                  Re: Cannot instantiate non-existent class

                  On Tue, 28 Feb 2006 11:04:59 -0800, julian_m wrote:
                  [color=blue]
                  > I'm having problems with include. I wrote a small example which shows
                  > what's going on...
                  >
                  > I should say that the problems started after I moved to a shared
                  > server. All was working fine in my local server...
                  >
                  >
                  > file test.php
                  > ---------------------------------------------------
                  > <?php
                  >
                  > echo '<html>';
                  > echo '<head>';
                  > echo '</head>';
                  > echo '<body>';
                  >
                  > echo "including inc.php<br>";
                  >
                  > include("http://my_site/inc.php");
                  >
                  > echo "inc was included<br>";
                  >
                  > $clsIncClass = new ClsIncClass;
                  >
                  > echo '</body>';
                  > echo '</html>';
                  >
                  > ?>
                  >
                  > file inc.php
                  > ---------------------------------------------------
                  > class ClsIncClass {
                  > function ClsIncClass() {
                  > echo "ClsIncClas s constructor<br> ";
                  > }
                  > }
                  >
                  >
                  > result in browser:
                  >
                  > including inc.php
                  > class ClsIncClass { function ClsIncClass() { echo "ClsIncClas s
                  > constructor
                  > "; } }inc was included
                  >
                  > Fatal error: Cannot instantiate non-existent class: clsincclass in
                  > /home/ke000067/public_html/test1.php on line 21
                  >
                  > Note that it seems that inc.php was included as if it were a text file,
                  > but as you can imagine, it's not my intention...
                  >
                  >
                  > So, i decided to change
                  >
                  > include("http://IP_of_my_site/inc.php");
                  >
                  > to
                  >
                  > include($_SERVE R['DOCUMENT_ROOT']."/my_site/inc.php");
                  >
                  > but the result was
                  >
                  > including inc.php
                  >
                  > including inc.php
                  >
                  > Warning: main(/opt/apache/htdocs/~ke000067/public_html/inc.php): failed
                  > to open stream: No such file or directory in
                  > /home/ke000067/public_html/test1.php on line 15
                  >
                  > Warning: main(/opt/apache/htdocs/~ke000067/public_html/inc.php): failed
                  > to open stream: No such file or directory in
                  > /home/ke000067/public_html/test1.php on line 15
                  >
                  > Warning: main(): Failed opening
                  > '/opt/apache/htdocs/~ke000067/public_html/inc.php' for inclusion
                  > (include_path=' .:/opt/apache/lib/php') in
                  > /home/ke000067/public_html/test1.php on line 15
                  > inc was included
                  >
                  > Fatal error: Cannot instantiate non-existent class: clsincclass in
                  > /home/ke000067/public_html/test1.php on line 23
                  >
                  >
                  > Anyone could give me some hints?
                  >
                  > regards - jm[/color]

                  Well, I don't know about anyone else, but I put <? ?> round php code in
                  included files. Would this make any difference?

                  Steve

                  Comment

                  Working...