Handling include() warnings

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

    Handling include() warnings

    I'm new to PHP and trying to get a handle on some basics.

    require() and include() both load up a file. require() exits if the
    inclusion fails while include() issues a warning and the script
    continues. In the latter situation how should I detect the failure?

    include('Foo.ph p');

    if (...) {
    Foo::do_somethi ng();
    } else {
    backup_action() ;
    }

    What should the test be? Can I catch the warning thrown by the
    include()? Should I search through get_included_fi les()? The
    file being included is a "standard" one which might be missing from an
    installation, so I can't edit it to define a constant in it.
    --
    Pete Forman -./\.- Disclaimer: This post is originated
    WesternGeco -./\.- by myself and does not represent
    pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
    http://petef.port5.com -./\.- Hughes or their divisions.
  • kingofkolt

    #2
    Re: Handling include() warnings

    if (!include('Foo. php')) {
    print "ERROR";
    }

    "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
    news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=blue]
    > I'm new to PHP and trying to get a handle on some basics.
    >
    > require() and include() both load up a file. require() exits if the
    > inclusion fails while include() issues a warning and the script
    > continues. In the latter situation how should I detect the failure?
    >
    > include('Foo.ph p');
    >
    > if (...) {
    > Foo::do_somethi ng();
    > } else {
    > backup_action() ;
    > }
    >
    > What should the test be? Can I catch the warning thrown by the
    > include()? Should I search through get_included_fi les()? The
    > file being included is a "standard" one which might be missing from an
    > installation, so I can't edit it to define a constant in it.
    > --
    > Pete Forman -./\.- Disclaimer: This post is originated
    > WesternGeco -./\.- by myself and does not represent
    > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
    > http://petef.port5.com -./\.- Hughes or their divisions.[/color]


    Comment

    • kingofkolt

      #3
      Re: Handling include() warnings

      if (!include('Foo. php')) {
      print "ERROR";
      }

      "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
      news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=blue]
      > I'm new to PHP and trying to get a handle on some basics.
      >
      > require() and include() both load up a file. require() exits if the
      > inclusion fails while include() issues a warning and the script
      > continues. In the latter situation how should I detect the failure?
      >
      > include('Foo.ph p');
      >
      > if (...) {
      > Foo::do_somethi ng();
      > } else {
      > backup_action() ;
      > }
      >
      > What should the test be? Can I catch the warning thrown by the
      > include()? Should I search through get_included_fi les()? The
      > file being included is a "standard" one which might be missing from an
      > installation, so I can't edit it to define a constant in it.
      > --
      > Pete Forman -./\.- Disclaimer: This post is originated
      > WesternGeco -./\.- by myself and does not represent
      > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
      > http://petef.port5.com -./\.- Hughes or their divisions.[/color]


      Comment

      • kingofkolt

        #4
        Re: Handling include() warnings

        if (!include('Foo. php')) {
        print "ERROR";
        }

        "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
        news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=blue]
        > I'm new to PHP and trying to get a handle on some basics.
        >
        > require() and include() both load up a file. require() exits if the
        > inclusion fails while include() issues a warning and the script
        > continues. In the latter situation how should I detect the failure?
        >
        > include('Foo.ph p');
        >
        > if (...) {
        > Foo::do_somethi ng();
        > } else {
        > backup_action() ;
        > }
        >
        > What should the test be? Can I catch the warning thrown by the
        > include()? Should I search through get_included_fi les()? The
        > file being included is a "standard" one which might be missing from an
        > installation, so I can't edit it to define a constant in it.
        > --
        > Pete Forman -./\.- Disclaimer: This post is originated
        > WesternGeco -./\.- by myself and does not represent
        > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
        > http://petef.port5.com -./\.- Hughes or their divisions.[/color]


        Comment

        • kingofkolt

          #5
          Re: Handling include() warnings

          oops sorry for sending the same message three times. twas a misake...

          "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
          news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=blue]
          > I'm new to PHP and trying to get a handle on some basics.
          >
          > require() and include() both load up a file. require() exits if the
          > inclusion fails while include() issues a warning and the script
          > continues. In the latter situation how should I detect the failure?
          >
          > include('Foo.ph p');
          >
          > if (...) {
          > Foo::do_somethi ng();
          > } else {
          > backup_action() ;
          > }
          >
          > What should the test be? Can I catch the warning thrown by the
          > include()? Should I search through get_included_fi les()? The
          > file being included is a "standard" one which might be missing from an
          > installation, so I can't edit it to define a constant in it.
          > --
          > Pete Forman -./\.- Disclaimer: This post is originated
          > WesternGeco -./\.- by myself and does not represent
          > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
          > http://petef.port5.com -./\.- Hughes or their divisions.[/color]


          Comment

          • Rook

            #6
            Re: Handling include() warnings

            you might want to suppress the error generated by the failed include... and
            maybe display some useful info... or maybe not.

            if (!@include('Foo .php')) {
            exit('Error in file: ' . __FILE__ . ' on line: ' . __LINE__);
            }

            - Rook.

            "kingofkolt " <jessepNOSPAM@c omcast.net> wrote in message
            news:cXIvc.3120 $%F2.940@attbi_ s04...[color=blue]
            > if (!include('Foo. php')) {
            > print "ERROR";
            > }
            >
            > "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
            > news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=green]
            > > I'm new to PHP and trying to get a handle on some basics.
            > >
            > > require() and include() both load up a file. require() exits if the
            > > inclusion fails while include() issues a warning and the script
            > > continues. In the latter situation how should I detect the failure?
            > >
            > > include('Foo.ph p');
            > >
            > > if (...) {
            > > Foo::do_somethi ng();
            > > } else {
            > > backup_action() ;
            > > }
            > >
            > > What should the test be? Can I catch the warning thrown by the
            > > include()? Should I search through get_included_fi les()? The
            > > file being included is a "standard" one which might be missing from an
            > > installation, so I can't edit it to define a constant in it.
            > > --
            > > Pete Forman -./\.- Disclaimer: This post is originated
            > > WesternGeco -./\.- by myself and does not represent
            > > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
            > > http://petef.port5.com -./\.- Hughes or their divisions.[/color]
            >
            >[/color]


            Comment

            • Rook

              #7
              Re: Handling include() warnings

              you might want to suppress the error generated by the failed include... and
              maybe display some useful info... or maybe not.

              if (!@include('Foo .php')) {
              exit('Error in file: ' . __FILE__ . ' on line: ' . __LINE__);
              }

              - Rook.

              "kingofkolt " <jessepNOSPAM@c omcast.net> wrote in message
              news:cXIvc.3120 $%F2.940@attbi_ s04...[color=blue]
              > if (!include('Foo. php')) {
              > print "ERROR";
              > }
              >
              > "Pete Forman" <pete.forman@we sterngeco.com> wrote in message
              > news:7juo4ncp.f sf@wgmail2.gatw ick.eur.slb.com ...[color=green]
              > > I'm new to PHP and trying to get a handle on some basics.
              > >
              > > require() and include() both load up a file. require() exits if the
              > > inclusion fails while include() issues a warning and the script
              > > continues. In the latter situation how should I detect the failure?
              > >
              > > include('Foo.ph p');
              > >
              > > if (...) {
              > > Foo::do_somethi ng();
              > > } else {
              > > backup_action() ;
              > > }
              > >
              > > What should the test be? Can I catch the warning thrown by the
              > > include()? Should I search through get_included_fi les()? The
              > > file being included is a "standard" one which might be missing from an
              > > installation, so I can't edit it to define a constant in it.
              > > --
              > > Pete Forman -./\.- Disclaimer: This post is originated
              > > WesternGeco -./\.- by myself and does not represent
              > > pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
              > > http://petef.port5.com -./\.- Hughes or their divisions.[/color]
              >
              >[/color]



              Comment

              • Pete Forman

                #8
                Re: Handling include() warnings

                Thanks for all the replies, even if they were from only 2 people ;-)

                My requirement is to to use a module if it is available, otherwise
                work round it. So using @ to suppress warnings is appropriate.

                $foo_available = @include('Foo.p hp');

                if ($foo_available ) {
                Foo::do_somethi ng();
                } else {
                backup_action() ;
                }

                --
                Pete Forman -./\.- Disclaimer: This post is originated
                WesternGeco -./\.- by myself and does not represent
                pete.forman@wes terngeco.com -./\.- opinion of Schlumberger, Baker
                http://petef.port5.com -./\.- Hughes or their divisions.

                Comment

                Working...