php-general Digest 11 Sep 2004 22:52:21 -0000 Issue 2990
Topics (messages 196392 through 196419):
Re: cURL Help - Posting a Form
196392 by: Nick Wilson
Re: Perplexing problem, suggestions or answer needed
196393 by: Wouter van Vliet
196399 by: Mag
Re: creating multiple sessions
196394 by: Torsten Roehr
Re: Help With PEAR::DB Connection
196395 by: James Kaufman
gettext does not translate
196396 by: Christian David
196401 by: Yann Larrivée
196403 by: Christian David
196416 by: Catalin Trifu
196418 by: Christian David
Re: create and read array
196397 by: John Taylor-Johnston
196408 by: Alexander Kleshchevnikov
196409 by: M. Sokolewicz
Re: [Newbie Guide] For the benefit of new members
196398 by: John Taylor-Johnston
196400 by: Greg Donald
Re: "no-store" and "no-cache" = no files in browser"s cache ?
196402 by: Christian David
Class dependencies
196404 by: Ed Lazor
196407 by: Curt Zirzow
196414 by: Ed Lazor
196417 by: Greg Beaver
Re: how to redirect ?
196405 by: Alexander Kleshchevnikov
196406 by: Alexander Kleshchevnikov
196411 by: Paul Waring
Enabling PHP5's SOAP on Windows
196410 by: John Smith
196412 by: Curt Zirzow
196415 by: Ed Lazor
Re: GD Library list
196413 by: Curt Zirzow
antique PHP problem
196419 by: Lowell Allen
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
* and then Nick Wilson declared....
> hi all,
>
> Im trying to get the following php code to output the
> 'success'/'failure' page from posting a form to a site. The problem is
Hmmmm... it helps if you are submitting to the 'action' url of
course.... sigh....
--
Nick W
--- End Message ---
--- Begin Message ---
On Sat, 11 Sep 2004 03:11:08 -0700 (PDT), Mag <[EMAIL PROTECTED]> wrote:
>
> --- John Holmes <[EMAIL PROTECTED]> wrote:
>
> > Mag wrote:
> >
> > > Hi,
> > > I will be getting input from a textarea and then I
> > am
> > > using "explode" to break the text into an array
> > when
> > > it encounters a space.
> > >
> > > eg:
> > > one two three four ninty
> > > would be broken into 5 parts of an array.
> > >
> > > ** The array would then be put into a session **
> > > now I need to display the last part (which would
> > be
> > > "ninty" using the above example) then take out the
> > > last part from the array then echo the next last
> > part
> > > (which would be "four") then take out the last
> > part
> > > (using unset? ) etc etc so I have something like:
> > >
> > > Displaying Array :
> > > ninty
> > > (deleteing ninty)
> > > four
> > > (deleteing four)
> > > three
> > > (deleteing three)
> > > etc
> > >
> > > I have been reading the manual and have come this
> > far,
> > > then I think I have to use the array splice
> > function..
> > > Am totally confused, any help, links, tutorials,
> > > pointers, tips or code would be appreciated.
> >
> > Why not just use array_reverse() and then print them
> > out in order using
> > foreach?
> >
> > --
> >
> > ---John Holmes...
>
> Hello John,
> The reason is I am trying to "chain" some programs,
> the idea is to take the first part (in the original
> example "ninty", then redirect to the second script
> passing that value...after the second script finishes
> it redirects back to the first script which will pass
> the second value (which would be "four") which would
> be be passed to the second script etc
>
> I think the main part which is confusing me is how I
> can take out just certain "used" parts of the array in
> the $_SESSION array...ideas?
>
> Thanx,
> Mag
>
I guess you're looking for array_pop(), it pops the last element off
the end of the array. Look it up in the manual to convince yourself.
--- End Message ---
--- Begin Message ---
> > Hello John,
> > The reason is I am trying to "chain" some
> programs,
> > the idea is to take the first part (in the
> original
> > example "ninty", then redirect to the second
> script
> > passing that value...after the second script
> finishes
> > it redirects back to the first script which will
> pass
> > the second value (which would be "four") which
> would
> > be be passed to the second script etc
> >
> > I think the main part which is confusing me is how
> I
> > can take out just certain "used" parts of the
> array in
> > the $_SESSION array...ideas?
> >
> > Thanx,
> > Mag
> >
>
> I guess you're looking for array_pop(), it pops the
> last element off
> the end of the array. Look it up in the manual to
> convince yourself.
Thanks for the tip, will do.
Cheers,
-Mag
=====
------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
--- End Message ---
--- Begin Message ---
>"John Gostick" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>Hi,
>
>I've encountered a situation where I need to have two or more SEPARATE
sessions running in separate windows. The reasons >are complicated, so I'll
keep things simple by just explaining the problem!
>
>Unfortunately my understanding of sessions is a little sketchy at best so
please stick with me...
>
>As I understand it, you can start a new session by manually opening another
separate Internet Explorer window, but I wish >the new session to start in a
window I've opened automatically from a previous page. Unfortunately this
appears to carry >on the session from the source window, which I don't
want - I want a new, separate session.
>
>I've considered calling session_start(); in the new window, then
destroying the session and calling session_start(); to >start a new,
separate session, but surely this will destroy the session in the original
window, which I want to keep >intact!
>
>So put simply, is there anyway to 'force' a new session?
>
>Thanks,
>
>John
Hi John,
this problem was discussed some days ago on this list. Please search the
archives. If those messages don't help come back again.
Best regards, Torsten Roehr
--- End Message ---
--- Begin Message ---
On Sat, Sep 11, 2004 at 01:48:43AM -0500, [EMAIL PROTECTED] wrote:
> Hello everyone,
>
> I have a problem connecting to the Database. When I execute the code at the
> bottom, it gives me this message: "DB Error: extension not found". It sees
> the DB file and the parameters are correct. I checked the include path and
> it was correct. Did I do something wrong? Any help would be greatly
> appreciated. Thank you.
>
>
> require_once 'DB.php';
> $user = 'foo';
> $pass = 'bar';
> $host = 'localhost';
> $db_name = 'clients_db';
> $dsn = "mysql://$user:[EMAIL PROTECTED]/$db_name";
> $db = DB::connect($dsn);
> if (DB::isError($db)) {
> die ($db->getMessage());
> }
>
> -- Nilaab
>
The message 'extension not found' means that PEAR couldn't find the mysql db
extension. Hmm. In cases like this, create a phpinfo.php file as documented on
this list and see what shows up. Or, you can type at the command prompt: php
-i, then look for the MySQL extension in the output.
Also, you neglected to tell us what OS you are running, etc.
--
Jim Kaufman
Linux Evangelist
public key 0x6D802619
---
A dog teaches a boy fidelity, perseverance, and to turn around three
times before lying down.
-- Robert Benchley
--- End Message ---
--- Begin Message ---
Hello!
I wrote this skript, but gettext returns only the english string.
I could not find a bug at bugs.php.net, so I think I forgot something.
I have Debian Linux, PHP Version 4.3.4 and Gettext 0.14.1 (PHP and Gettext
as debian pakages)
gettext.php in /var/www/gymbay/
<?php
// Set language to German
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("messages", "i18n");
// Choose domain
textdomain("messages");
// Translation is (should) looking for in
i18n/de_DE/LC_MESSAGES/messages.mo now
// Print a test message
echo gettext("Welcome to My PHP Application");
// Or use the alias _() for gettext()
echo _("Have a nice day");
// Output:
// Welcome to My PHP ApplicationHave a nice day
?>
messages.po
# translation of messages.po to german
# This file is distributed under the same license as the PACKAGE package.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER.
# Christian DÃvid <[EMAIL PROTECTED]>, 2004.
#
msgid ""
msgstr ""
"Project-Id-Version: messages\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2004-09-11 15:50+0200\n"
"PO-Revision-Date: 2004-09-11 15:52+0200\n"
"Last-Translator: Christian DÃvid <[EMAIL PROTECTED]>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.3.1\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: gettext.php:15
msgid "Welcome to My PHP Application"
msgstr "Willkommen zu meiner PHP Anwendung"
#: gettext.php:18
msgid "Have a nice day"
msgstr "Wir wÃnschen Ihnen einen schÃnen Tag"
and the "messages.mo" is in /var/www/gymbay/i18n/de_DE/LC_MESSAGES/
Thank you!
--- End Message ---
--- Begin Message ---
Did you restart apache after creating your mo file ?
Look at the first comment on http://ca3.php.net/gettext
You might be facing this issue.
Yann
On September 11, 2004 10:08, Christian David wrote:
> Hello!
>
> I wrote this skript, but gettext returns only the english string.
>
> I could not find a bug at bugs.php.net, so I think I forgot something.
> I have Debian Linux, PHP Version 4.3.4 and Gettext 0.14.1 (PHP and Gettext
> as debian pakages)
>
> gettext.php in /var/www/gymbay/
>
> <?php
> // Set language to German
> setlocale(LC_ALL, 'de_DE');
>
> // Specify location of translation tables
> bindtextdomain("messages", "i18n");
>
> // Choose domain
> textdomain("messages");
>
> // Translation is (should) looking for in
> i18n/de_DE/LC_MESSAGES/messages.mo now
>
> // Print a test message
> echo gettext("Welcome to My PHP Application");
>
> // Or use the alias _() for gettext()
> echo _("Have a nice day");
>
> // Output:
> // Welcome to My PHP ApplicationHave a nice day
>
> ?>
>
> messages.po
>
> # translation of messages.po to german
> # This file is distributed under the same license as the PACKAGE package.
> # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER.
> # Christian DÃvid <[EMAIL PROTECTED]>, 2004.
> #
> msgid ""
> msgstr ""
> "Project-Id-Version: messages\n"
> "Report-Msgid-Bugs-To: \n"
> "POT-Creation-Date: 2004-09-11 15:50+0200\n"
> "PO-Revision-Date: 2004-09-11 15:52+0200\n"
> "Last-Translator: Christian DÃvid <[EMAIL PROTECTED]>\n"
> "Language-Team: \n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=UTF-8\n"
> "Content-Transfer-Encoding: 8bit\n"
> "X-Generator: KBabel 1.3.1\n"
> "Plural-Forms: nplurals=2; plural=(n != 1);\n"
>
> #: gettext.php:15
> msgid "Welcome to My PHP Application"
> msgstr "Willkommen zu meiner PHP Anwendung"
>
> #: gettext.php:18
> msgid "Have a nice day"
> msgstr "Wir wÃnschen Ihnen einen schÃnen Tag"
>
> and the "messages.mo" is in /var/www/gymbay/i18n/de_DE/LC_MESSAGES/
>
> Thank you!
pgpIjh9D9RLu7.pgp
Description: signature
--- End Message ---
--- Begin Message ---
Yann LarrivÃe wrote:
> Did you restart apache after creating your mo file ?
You are right, thank you.
But there where another mistake, too. My system doesn't like "de_DE", it
wants to have "[EMAIL PROTECTED]".
--- End Message ---
--- Begin Message ---
Hi,
I had really bad headaches with gettext some time ago
and since then I decided to no longer use it. It's unreliable on
heavy loads (mixed english + translated texts), moving the scritps to
another machine means more headache, it relies on system calls which
are not "isolated", which means scritps can step on each others toes.
My advice is stay away of gettext. Try some DB framework for
translation; it definetely performs better and more reliable.
Or, if the site is small you can rely on included files.
Cheers,
catalin
"Christian David" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello!
>
> I wrote this skript, but gettext returns only the english string.
>
> I could not find a bug at bugs.php.net, so I think I forgot something.
> I have Debian Linux, PHP Version 4.3.4 and Gettext 0.14.1 (PHP and Gettext
> as debian pakages)
>
> gettext.php in /var/www/gymbay/
>
> <?php
> // Set language to German
> setlocale(LC_ALL, 'de_DE');
>
> // Specify location of translation tables
> bindtextdomain("messages", "i18n");
>
> // Choose domain
> textdomain("messages");
>
> // Translation is (should) looking for in
> i18n/de_DE/LC_MESSAGES/messages.mo now
>
> // Print a test message
> echo gettext("Welcome to My PHP Application");
>
> // Or use the alias _() for gettext()
> echo _("Have a nice day");
>
> // Output:
> // Welcome to My PHP ApplicationHave a nice day
>
> ?>
>
> messages.po
>
> # translation of messages.po to german
> # This file is distributed under the same license as the PACKAGE package.
> # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER.
> # Christian D�vid <[EMAIL PROTECTED]>, 2004.
> #
> msgid ""
> msgstr ""
> "Project-Id-Version: messages\n"
> "Report-Msgid-Bugs-To: \n"
> "POT-Creation-Date: 2004-09-11 15:50+0200\n"
> "PO-Revision-Date: 2004-09-11 15:52+0200\n"
> "Last-Translator: Christian D�vid <[EMAIL PROTECTED]>\n"
> "Language-Team: \n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=UTF-8\n"
> "Content-Transfer-Encoding: 8bit\n"
> "X-Generator: KBabel 1.3.1\n"
> "Plural-Forms: nplurals=2; plural=(n != 1);\n"
>
> #: gettext.php:15
> msgid "Welcome to My PHP Application"
> msgstr "Willkommen zu meiner PHP Anwendung"
>
> #: gettext.php:18
> msgid "Have a nice day"
> msgstr "Wir w�nschen Ihnen einen sch�nen Tag"
>
> and the "messages.mo" is in /var/www/gymbay/i18n/de_DE/LC_MESSAGES/
>
> Thank you!
--- End Message ---
--- Begin Message ---
Catalin Trifu wrote:
> moving the scritps to
> another machine means more headache, it relies on system calls which
> are not "isolated", which means scritps can step on each others toes.
> MyÂadviceÂisÂstayÂawayÂofÂgettext.
Thanks for your advice!
I have tested the script on the Webserver, and fortunately it works!
I am using gettext because of the po Files. With programs like KBabel it is
no problem to translate them. The second reason is the Plural. I hate
sentences like '1 File(s) found!'.
I could not notice a loss of performance yet.
Christian
--- End Message ---
--- Begin Message ---
John,
The long expanation is I'm indexing 2000 records to make a list of each author, and
which record I can find them in. It's a bibliography thing. I want to do this, but I
don't know how to code it:
$array();
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
$news = mysql_query("select id,AUS from $table");
while ($mydata = mysql_fetch_object($news))
{
$tempauthors = explode(";", $mydata->AUS);
foreach ($tempauthors as $singleauthor)
{
-------having trouble here--------------
add $singleauthor and $mydata->id to $array
-------having trouble here--------------
}
}
mysql_close;
-------having trouble here--------------
foreach ($array as $single_AUS, $single_id)
$sql = 'insert into $db.$table2.($single_AUS, $single_id)';
-------having trouble here--------------
mysql_query($sql)
It's a little more complicated than that, but advice on coding this much would help.
John
P.S. my condoleances to New York today. Can't believe it was 3 years ago already.
John Holmes wrote:
> John Taylor-Johnston wrote:
> > 1. How do I write $mydata->AUS and $mydata->id into an array?
> >
> > $authors = array();
> > while ($mydata = mysql_fetch_object($news))
> > {
> > # echo "$mydata->AUS, $mydata->id\n";
> > ??? write to array
> > }
> > mysql_close($myconnection);
>
> What do you mean "write to array"??
>
> $array = array($mydata->AUS,$mydata->id);
>
> That?
>
> > 2. Then I need to create $SQL
> >
> > foreach ($authors as something)
> > {
> > $sql += "INSERT INTO newtable VALUES ($AUS, $id);\r\n";
> > }
>
> += is addition. I doubt that's what you want.
>
> $sql .= "INSERT INTO newtable VALUES ({$mydata->AUS},{$mydata->id});\r\n";
>
> Not sure why you're joining all these queries together, you can only run
> one at a time with MySQL...
>
> --
>
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals � www.phparch.com
--
John Taylor-Johnston
-----------------------------------------------------------------------------
"If it's not open-source, it's Murphy's Law."
' ' ' Coll�ge de Sherbrooke:
��� http://www.collegesherbrooke.qc.ca/languesmodernes/
- Universit� de Sherbrooke:
http://compcanlit.ca/
819-569-2064
--- End Message ---
--- Begin Message ---
Maybe you want this:
while ($data = mysql_fetch_assoc($news)) {
$sql += "INSERT INTO newtable VALUES ($data['AUS'], $data['id']);\r\n";
}
If you nevertheless want save the data in array you can use a
two-dimensional array $authors:
$authors = array();
while ($data = mysql_fetch_assoc($news)) {
$authors[] = array('AUS' => $data['AUS'], 'id' => $data[id]);
}
..
foreach ($author in $authors) {
$sql += "INSERT INTO newtable VALUES ($author['AUS'],
$author['id']);\r\n";
}
--
Seigo
www.geocities.com/seigo_ua/
"John Taylor-Johnston" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Can someone help me, show me how to do this please?
>
> 1. How do I write $mydata->AUS and $mydata->id into an array?
>
> $authors = array();
> while ($mydata = mysql_fetch_object($news))
> {
> # echo "$mydata->AUS, $mydata->id\n";
> ??? write to array
> }
> mysql_close($myconnection);
>
> 2. Then I need to create $SQL
>
> foreach ($authors as something)
> {
> $sql += "INSERT INTO newtable VALUES ($AUS, $id);\r\n";
> }
>
> I am reading http://ca3.php.net/manual/en/language.types.array.php but
don't really get it.
>
> Can I do $sql += "blah"; or do I have to write $sql = $sql + "blah";?
--- End Message ---
--- Begin Message ---
Alexander Kleshchevnikov wrote:
Maybe you want this:
while ($data = mysql_fetch_assoc($news)) {
$sql += "INSERT INTO newtable VALUES ($data['AUS'], $data['id']);\r\n";
}
I seriously recommend using .= on strings instead of +=. += DOES work,
that's true, but it's not INTENDED to be used on strings, rather to be
used on arrays and numbers.
If you nevertheless want save the data in array you can use a
two-dimensional array $authors:
$authors = array();
while ($data = mysql_fetch_assoc($news)) {
$authors[] = array('AUS' => $data['AUS'], 'id' => $data[id]);
}
..
foreach ($author in $authors) {
$sql += "INSERT INTO newtable VALUES ($author['AUS'],
$author['id']);\r\n";
}
--
Seigo
www.geocities.com/seigo_ua/
"John Taylor-Johnston" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Can someone help me, show me how to do this please?
1. How do I write $mydata->AUS and $mydata->id into an array?
$authors = array();
while ($mydata = mysql_fetch_object($news))
{
# echo "$mydata->AUS, $mydata->id\n";
??? write to array
}
mysql_close($myconnection);
2. Then I need to create $SQL
foreach ($authors as something)
{
$sql += "INSERT INTO newtable VALUES ($AUS, $id);\r\n";
}
I am reading http://ca3.php.net/manual/en/language.types.array.php but
don't really get it.
Can I do $sql += "blah"; or do I have to write $sql = $sql + "blah";?
--- End Message ---
--- Begin Message ---
Thanks. As a newbie, something I like to try also is making a second file with phps as
the extension.
Sometimes reading my code in colour helps me see things better. Sometimes I forget a
semi-colon ";" and will see the problem immediately.
Ma Sivakumar wrote:
> =======================================
> Please feel free to add more points and send
> to the list.
> =======================================
>
> 1. If you have any queries/problems about PHP
> try http://www.php.net/manual/en first. You
> can download a copy and use it offline also.
>
--- End Message ---
--- Begin Message ---
On Sat, 11 Sep 2004 10:41:49 -0400, John Taylor-Johnston
<[EMAIL PROTECTED]> wrote:
> Thanks. As a newbie, something I like to try also is making a second file with phps
> as the extension.
> Sometimes reading my code in colour helps me see things better. Sometimes I forget a
> semi-colon ";" and will see the problem immediately.
So save yourself a lot of time and get a colorful editor like vim or
editplus or something.. :)
--
Greg Donald
http://destiney.com/
--- End Message ---
--- Begin Message ---
Bart Coninckx wrote:
> header('Cache-Control:Âno-store,Âno-cache,Âmust-revalidate');Â//
> HTTP/1.1
> header('Cache-Control:Âpost-check=0,Âpre-check=0');Â//ÂdamnableÂIE5
You overwrite the first Cache-Control command, use:
header("Cache-Control: post-check=0, pre-check=0", false);
Now both Cache-Control commands are being sent.
Christian
--- End Message ---
--- Begin Message ---
I'm creating classes that rely on the presence of other classes that I've
created. Does PHP5 provide a way to specify these dependencies or a way to
check these dependencies when the class is instantiated? For example, class
Automobile would fail to instantiate if class Tire wasn't available.
I know the __autoload feature of PHP5 could be used to flag an error like
this:
function __autoload($class_name) {
if ([EMAIL PROTECTED]("$class_name.php")) {
echo "Error: Unable to load $class_name.<br>";
}
}
This solution may work to some degree, but it doesn't tell me which class
depended on the missing class, which would be helpful in troubleshooting.
Also, it seems like you'd want to check dependencies first thing, rather
than getting part way through the application before having an error occur.
What do you think? What approaches do you guys use on this?
Thanks,
Ed
--- End Message ---
--- Begin Message ---
* Thus wrote Ed Lazor:
> I'm creating classes that rely on the presence of other classes that I've
> created. Does PHP5 provide a way to specify these dependencies or a way to
> check these dependencies when the class is instantiated? For example, class
> Automobile would fail to instantiate if class Tire wasn't available.
>
> I know the __autoload feature of PHP5 could be used to flag an error like
> this:
>
> function __autoload($class_name) {
> if ([EMAIL PROTECTED]("$class_name.php")) {
> echo "Error: Unable to load $class_name.<br>";
> }
> }
What you can do is something like this:
function __autoload($class_name) {
static $_stack = array();
// push the calls of autoload here
array_push($_stack, $class_name);
if ( [EMAIL PROTECTED]("$class_name.php") ||
!class_exists($class_name, false) ) {
var_dump($_stack);
$_stack = array(); // reset it
echo "Error: Unable to load $class_name.<br>";
return false;
}
// pop the stack
array_pop($_stack);
return true;
}
Curt
--
The above comments may offend you. flame at will.
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> What you can do is something like this:
>
>
1> function __autoload($class_name) {
2> static $_stack = array();
3>
4> // push the calls of autoload here
5> array_push($_stack, $class_name);
6>
7> if ( [EMAIL PROTECTED]("$class_name.php") ||
8> !class_exists($class_name, false) ) {
9>
10> var_dump($_stack);
11> $_stack = array(); // reset it
12> echo "Error: Unable to load $class_name.<br>";
13>
14> return false;
15> }
16>
17> // pop the stack
18> array_pop($_stack);
19>
20> return true;
21>
22> }
Hi Curt =)
This didn't seem to work. The stack stuff just ends up dumping the value of
$class_name. Also, why check to see if the class exists on line #8? Isn't
PHP calling __autoload already confirming that the class doesn't exist?
I'll include copies of the two scripts below. Here's information on the
scripts that might help explain things.
The first script is being saved as Test.php. It includes a class called
Test.
The second script is being saved as test2.php. This script has a class
called ClassDependent. It depends on the Test class.
I'm trying to address two situations are being addressed here. What if the
file Test.php is missing for some reason. And, even if the file is present,
what happens if the file / class hasn't been loaded?
In my opinion, if class Test is missing, it makes sense to know up front.
It provides a sort of checks and balances. Otherwise, the class doesn't
show as missing until there's an attempt to load it. I can easily see
deploying an app without realizing there's a problem until someone happens
to use some osbure feature that depends on the missing class.
Maybe I'm being paranoid (opinions? - be nice :P hehe), but once reason I'm
looking into using OOP is to reduce bugs and I'm just looking at possible
pitfalls. It would be nice to hear how you guys handle this with PHP-based
apps that you deploy.
I know that I could just create a list of files belonging to the app and
check to make sure that they are all present when starting. It seems like
there could be a lot of overhead in maintaining something like this. It
also seems to make sense that you'd want classes to define their own
dependencies for portability. What do you think?
All of this kind of leads into why I'd like autoload (or some other tool) to
indicate which class ran into a problem loading another class. In the
examples below, it helps troubleshoot things if the error message tells me
that ClassDependent was unable to load class Test. Hehe Having the error
message tell me which line number would also be super cool, but maybe that's
not possible.
Anyway, I look forward to hearing what you guys think.
Thanks,
Ed
Scripts:
---------------------------------
Test.php
---------------------------------
<?php
class Test {
public $value1 = 0;
function set_value1($data) {
$this->value1 = $data;
}
function get_value1() {
return $this->value1;
}
}
?>
---------------------------------
Test2.php
---------------------------------
<?php
function __autoload($class_name) {
static $_stack = array();
// push the calls of autoload here
array_push($_stack, $class_name);
if ( [EMAIL PROTECTED]("$class_name.php") ||
!class_exists($class_name, false) ) {
var_dump($_stack);
$_stack = array(); // reset it
echo "Error: Unable to load $class_name.<br>";
return false;
}
// pop the stack
array_pop($_stack);
return true;
}
class ClassDependent {
private $MyObject;
function ClassDependent() {
$this->MyObject = new Test;
}
function get_name() {
return $this->MyObject->get_value1();
}
function set_name($data) {
return $this->MyObject->set_value1($data);
}
}
$temp = new ClassDependent;
$temp->set_name("Ed");
print "This is a test... " . $temp->get_name() . "<br>";
?>
--- End Message ---
--- Begin Message ---
Ed Lazor wrote:
I'm creating classes that rely on the presence of other classes that I've
created. Does PHP5 provide a way to specify these dependencies or a way to
check these dependencies when the class is instantiated? For example, class
Automobile would fail to instantiate if class Tire wasn't available.
PHP5 does not, but PEAR was created specifically to solve this problem.
All you need to do is package your modular classes as packages, and
then people can use the pear installer to enforce the dependencies prior
to runtime. Then, at runtime, all you have to do is assume they are
there, as the user can't install your class without the presence of the
others (well, they can, but it requires some monkey business and they
would have to know that it failed)
Greg
--- End Message ---
--- Begin Message ---
Hey!
I think you used header() after put out some data or php installed on server
as CGI. Because send header possible only if php installed as apache module.
You can use custom function which use javascript for redirection. But it
works if browser of client support javascript:
function redirect(path) {
echo '<script type="text/javascript">window.location='.path.'</script>';
exit();
}
--
"Cbharadwaj" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi
I have used
Header (Location:PATH) function for redirection.
it is giving some errors.
is there any other method other than HEADER() funtion for redirecting ?
Bharadwaj
--- End Message ---
--- Begin Message ---
Hey!
I think you used header() after put out some data or php installed on server
as CGI. Because send header possible only if php installed as apache module.
You can use custom function which use javascript for redirection. But it
works if browser of client support javascript:
function redirect(path) {
echo '<script type="text/javascript">window.location='.path.'</script>';
exit();
}
--
"Cbharadwaj" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi
I have used
Header (Location:PATH) function for redirection.
it is giving some errors.
is there any other method other than HEADER() funtion for redirecting ?
Bharadwaj
--- End Message ---
--- Begin Message ---
> I think you used header() after put out some data or php installed on server
> as CGI. Because send header possible only if php installed as apache module.
Not so - I've used header('Location: http://www.xyz.com/'); with PHP
as a CGI binary under both Apache 1 and Apahce 2 without problems.
Paul
--- End Message ---
--- Begin Message ---
How can I enable PHP5's native SOAP, without
presumably compiling PHP5 from source? I don't see an
extension for it in php.ini
John
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--- End Message ---
--- Begin Message ---
* Thus wrote John Smith:
> How can I enable PHP5's native SOAP, without
> presumably compiling PHP5 from source? I don't see an
> extension for it in php.ini
This should work as long as php is installed properly:
extension=php_soap.dll
Curt
--
The above comments may offend you. flame at will.
--- End Message ---
--- Begin Message ---
Add to php.ini
Extension=php_soap.dll
I didn't see a line in php.ini to uncomment, but I found a page that
confirmed this:
http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Windows/Q_21080398
.html
> -----Original Message-----
> From: John Smith [mailto:[EMAIL PROTECTED]
> Sent: Saturday, September 11, 2004 12:05 PM
> To: PHP General
> Subject: [PHP] Enabling PHP5's SOAP on Windows
>
> How can I enable PHP5's native SOAP, without
> presumably compiling PHP5 from source? I don't see an
> extension for it in php.ini
>
> John
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
* Thus wrote bskolb:
> Does anyone know if there is a mailing list for gdlib? Can't seem to find
> in Google.
This is there homepage:
http://www.boutell.com/gd/
I dont see any list there though.
Curt
--
The above comments may offend you. flame at will.
--- End Message ---
--- Begin Message ---
I'm doing a project on a server with an old version of PHP -- 4.0.6 on
Apache 1.3.22 on FreeBSD and I'm having a problem with session
variables. From code in a script that receives a post:
-----
session_start();
$HTTP_SESSION_VARS["m_name"] = get_magic_quotes_gpc() ?
stripslashes($HTTP_POST_VARS["m_name"]) : $HTTP_POST_VARS["m_name"];
-----
Then later I can successfully echo the posted value with:
-----
htmlentities($HTTP_SESSION_VARS["m_name"])
-----
The posted value is shown as expected, which means the session variable
is set, right? At the end of the receiving script page I have a link
back to the form where the values were posted from, and in the original
form I check for session variables in order to re-populate the form
with them if they're present:
-----
session_start();
$m_name = isset($HTTP_SESSION_VARS["m_name"]) ?
$HTTP_SESSION_VARS["m_name"] : "";
-----
Then in the original HTML form field:
-----
<?php echo($m_name); ?>
-----
But $m_name == "" and the field is blank.
The same code works as expected on a different server running PHP 4.3.8
on Apache 1.3.31 on Linux. I think I'm stuck with 4.0.6 for this
project. I'd appreciate any suggestions on what I should check/advice
on using $HTTP_SESSION_VARS.
--
Lowell Allen
--- End Message ---