You are here: Re: remote include doesn't work with class « All PHP « IT news, forums, messages
Re: remote include doesn't work with class

Posted by Rik on 08/01/07 17:33

On Wed, 01 Aug 2007 19:26:50 +0200, charliefortune
<google@charliefortune.com> wrote:

> On 1 Aug, 17:30, ZeldorBlat <zeldorb...@gmail.com> wrote:
>> On Aug 1, 12:19 pm, charliefortune <goo...@charliefortune.com> wrote:
>>
>>
>>
>> > On 1 Aug, 17:16, Rik <luiheidsgoe...@hotmail.com> wrote:
>>
>> > > On Wed, 01 Aug 2007 18:04:14 +0200, charliefortune
>>
>> > > <goo...@charliefortune.com> wrote:
>> > > > I have been including local .php files in a script succesfully
>> for a
>> > > > while. But now I want it to be a remote include i.e.
>>
>> > > > include ("http://myserver.co.uk/includes/classLib.php");
>>
>> > > > and I get
>>
>> > > > Cannot instantiate non-existent class:
>>
>> > > > I know the path is correct because if I include simply a line of
>> text
>> > > > to echo then it works fine. Are there any issues with variable
>> scope
>> > > > when including remote classes please ? My class definition is
>> simply
>>
>> > > > class AdminLib {
>> > > > blah blah;
>> > > > blah;
>> > > > blah;
>> > > > }
>>
>> > > > do I have to declare it global or anything ? Thanks.
>>
>> > > If the include works fine (no allow_url_fopen or the remote include
>> > > thingy): don't forget they need to start & end with php opening &
>> closing
>> > > tags... Else it's 'just content'.
>>
>> > > Class definitions have no scope, allthough PHP6 might have support
>> for
>> > > namespaces.
>>
>> > The include is wrapped in <?php ?> tags so that's not the problem. I
>> > don't know about the allow_url_fopen stuff. Is there an fread
>> > alternative I could do to read the file and eval() it perhaps, just to
>> > get it working ?
>>
>> When you do a remote include like that the you usually don't get the
>> actual code back since the remote server is typically configured to
>> run it through PHP before sending the output. Suppose your remote
>> file has this in it:
>>
>> <?php
>> class Foo {
>>
>> }
>>
>> ?>
>>
>> If you request that file in your browser what do you get? You get
>> nothing since that script has no output. So, when you do the include,
>> he doesn't get any output either.
>>
>> Remember: when you request a PHP file through a webserver you don't
>> actually get the PHP code back -- you get the output of the PHP script
>> back.
>
> When I go to the url, I get nothing because, like you say, the script
> doesn't produce anything, it is just a single class definition, and is
> being parsed before being returned.


On the server with the definition:
file: givememyclassdefinitioninplainphp.php
<?php
readfile('myClass.php');
?>

Then again, I would never never never get class definitions this way. Too
much overhead, huge security risks, slow, waiting for a
connection-error/incomplete file to happen etc.

>
> So how does one go about reusing class definitions from remote
> sources please ?
>

I would keep a local copy, keep a CVS or SVN repository of the class
definitions, and update now and then according to need.


--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация