Re: [PHP] PEAR segfaulting

2009-10-19 Thread Greg Beaver
Ashley M. Kirchner wrote:
> 
>Well, it boiled down to zlib.so causing the segfault.  As soon as I
> removed that module, everything worked.  Recompiling just the zlib.so
> module yielded the same result: pear segfaults.
> 
>So now the question is: is it zlib's fault, or is it pear?
> 
>At this point I've accomplished what I needed, but it doesn't
> actually fix the problem: enabling zlib will cause pear to segfault.

Ha, I guess I should wait before replying :).

It is zlib's fault.  We've had reported problems for years on some
poorly configured systems (not your problem: several distros decided to
include a borked zlib and apparently some still do for no good reason at
all).

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PEAR segfaulting

2009-10-19 Thread Greg Beaver
Ashley M. Kirchner wrote:
> 
>Typing 'pear segmentation fault' in Google produces tons of responses
> so I know I'm not the only one with this issue, but I'll be damned if I
> can figure out what the problem is and how to fix it.  I rolled my own
> PHP 5.3.0 from source.  Compilation went fine, no errors.  Installation
> went without any errors.  I can run 'pecl' and install some packages,
> but when I try to run 'pear', it segfaults after it downloads a package:
> 
> 
> $ pear install DB
> WARNING: "pear/DB" is deprecated in favor of "pear/MDB2"
> downloading DB-1.7.13.tgz ...
> Starting to download DB-1.7.13.tgz (132,246 bytes)
> .done: 132,246 bytes
> Segmentation fault
> 
> 
> 
>Running it with -vvv gives me:
> 
> 
> $ pear -vvv install DB
> 
> Warning: file_exists(): Unable to find the wrapper "channel" - did you
> forget to enable it when you configured PHP? in
> PEAR/Downloader/Package.php on line 1510
> 
> Warning: is_file(): Unable to find the wrapper "channel" - did you
> forget to enable it when you configured PHP? in
> PEAR/Downloader/Package.php on line 1520
> 
> Warning: is_file(): Unable to find the wrapper "channel" - did you
> forget to enable it when you configured PHP? in
> PEAR/Downloader/Package.php on line 1520
> WARNING: "pear/DB" is deprecated in favor of "pear/MDB2"
> pear/DB: Skipping required dependency "pear/PEAR" version 1.9.0, already
> installed as version 1.8.0
> Downloading "http://pear.php.net/get/DB-1.7.13.tgz";
> downloading DB-1.7.13.tgz ...
> Starting to download DB-1.7.13.tgz (132,246 bytes)
> .done: 132,246 bytes
> Segmentation fault
> 
> 
> 
>So, is this a known issue?

Hi,

Most likely your machine has a borked zlib library.  Try:

pear install -Z DB

This will download the uncompressed .tar and should work fine.  If it
does, look to fix your zlib install and re-build PHP.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Re: Re: Design Patterns

2009-08-13 Thread Greg Beaver
Robert Cummings wrote:
> 
> 
> Martin Zvarík wrote:
>> Ralph Deffke napsal(a):
>>> NO NO NO
>>>
>>> OOP is the best ever inventet !
>>>
>>> see my comments on this list, I will also come up with an pure oop
>>> opensource OMS very soon.
>>>
>>> I just think a dam big pattern catalog like this one is like an elephant
>>> chacing mice. I mean I can think of customers asking for a
>>> documentation of
>>> course of the page u created for them calling the next day asking
>>> wher the
>>> hell are the code for the page are documented in the 1000 pages of
>>> documentation u had to give them.
>>>
>>> I can think of two of my largest customers with their intranet
>>> application
>>> with 23000 members and more then 5 hits during working hours where I
>>> startet sweating while figting for every 1ms.
>>>
>>> I'm thinking of people with even more hits a day, they even dont
>>> start using
>>> PHP
>>> so I dont know if thats the right way to blow up with includes  and
>>> thousands of classes.
>>
>> I deeply and completely agree.
> 
> Yes, certainly optimize on an as-needed basis. But well written PHP code
> should certainly scale quite well horizontally. Extremely traffic laden
> websites are quite likely to see a bottleneck at the database before a
> bottleneck in the code.

Hi,

You all should understand that on high traffic sites, C or C++ is far
more frequently used and called "PHP" because they use a whole lot of
custom extensions to speed things up.  In addition, memcached speeds up
database access so much that the speed of PHP starts to matter.  This is
why PHP 5.3.0 is somewhere around 30% faster than any previous PHP
version when running common applications, because the core developers
realized that the base efficiency begins to matter and spent
considerable effort improving basic language performance.

There are a lot of ways to improve PHP's efficiency, and arguing over
whether to use design patterns is not a particularly effective one.
Profiling early and often to understand the slowest portions of your
code is an effective method.  There are many, many talks/videos/etc.
that can be found via google.com which discuss these principles, but
suffice to say that xdebug, APC, and most importantly siege and apache
benchmark are your friends in this endeavor.

For Ralph: it might help you to know that facebook.com improved their
performance by splitting up things into lots and lots of classes, and
using autoload.  I don't have specific details because I don't work
there, but the programmer who coded this solution was telling me the
generalities at php|tek 2 years ago.  The pages that saw improvement
were ones with a large number of possible execution branches in
different requests.  autoload simply reduced the number of needed files
to the bare minimum from a wide variety of choices.

This surprised me, because the prevailing opinion at the time was that
autoload always reduces performance.  The point to take from this story
is that what you think to be true doesn't matter, the only thing is
really understanding where your bottlenecks are by profiling
aggressively, and even more important, why its slow, so you can fix it.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] This is the kind of [expletives deleted] answer that iscertain to prevent bugs being reported.

2009-07-24 Thread Greg Beaver
Robert Cummings wrote:

> I understand where you're coming from, and I've been on the same road
> before with PHP bug reports. And while I remember being really annoyed,
> especially when it turned out to actually be a bug, I have to say if you
> define your case clearly and state where either the documentation isn't
> clear enough, or the code works in an unexpected fashion, then they will
> usually give it the due consideration. Don't forget nobody is being paid
> to handle bug reports, it's all on a volunteer basis and I'm quite
> certain they get oodles of real bogus bugs.

Hi,

I suggest anyone with a casual interest in understanding where php
developers who respond to bugs are coming from, just read the reports
and comments as they come through the php-bugs list (php.bugs on the
news server).

Watch how many obvious bugs with issues (i.e. bogus bugs) come through,
and note what the rate of mis-judgements by the devs responding to bugs
is, it is very very low, but not 0%.

You'll also notice Jani responds to almost everything, either assigning
it to someone, or closing the ones he sees as obvious for one reason or
another.

You'll also notice that both he and users can be far more acidic than
the canned responses, and yes - if you have a suggestion for improving a
canned response, it will be taken seriously.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP as Language

2009-07-24 Thread Greg Beaver
Martin Scotta wrote:
> Hi all
> 
> Is there a formal definition for the php language?
> Where I can found it?
> 
> I've STW with no results.

http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_language_parser.y?revision=281094&view=markup

which is Zend/zend_language_parser.y in the source code of PHP.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Renaming all variables in a repository

2009-07-23 Thread Greg Beaver
Eddie Drapkin wrote:
> Hey all,
> we've got a repository here at work, with something like 55,000 files
> in it. For the last few years, we've been naming $variables_like_this
> and functions_the_same($way_too).  And now we've decided to switch to
> camelCasing everything and I've been tasked with somehow determining
> if it's possible to automate this process.  Usually, I'd just use the
> IDE refactoring functionality, but doing it on a
> per-method/per-function and a per-variable basis would take weeks, if
> not longer, not to mention driving everyone insane.
> 
> I've tried with regular expressions, but I can't make them smart
> enough to distinguish between builtins and userland code.  I've looked
> at the tokenizer and it seems to be the right way forward, but that's
> also a huge project to get that to work.
> 
> I was wondering if anyone had had any experience doing this and could
> either point me in the right direction or just down and out tell me
> how to do it.

Hi Eddie,

That's quite the task :).

You're going to need to scan the source to generate a list of every
variable and function name using the tokenizer.  Fortunately, this is
easy - with the caveat that if you do this anywhere in your source:

$a = $this->{$constructed . '_name'}();

you will have to handle these manually.

Basically, run token_get_all() on the source, scanning for T_VARIABLE,
and record every T_VARIABLE in an array.  Then, scan for:

1) T_FUNCTION T_WHITESPACE* T_STRING
2) T_OBJECT_OPERATOR T_WHITESPACE* T_STRING

 $file) {
$source = file_get_contents($path);

$checkForID = false;
$var = false;
$last = '';
foreach (token_get_all($source) as $token) {
if (!is_array($token)) continue;

if ($checkForID) {
if ($token[0] == T_WHITESPACE) {
$last .= $token[1];
continue;
}
if ($token[0] != T_STRING) {
$checkForID = false;
$last = '';
continue;
}
$token[1] = $last . $token[1];
} elseif ($token[0] == T_FUNCTION || $token[0] == T_OBJECT_OPERATOR) {
$checkForID = true;
$last = $token[1];
continue;
} elseif ($token[0] == T_STRING) {
if (function_exists($token[1])) {
continue; // skip internal functions
}
if (strtolower($token[1]) != $token[1]) {
continue; // assuming you UPPER-CASE constants, this skips them
}
} elseif ($token[0] != T_VARIABLE) {
continue;
}

// we get to here if we've found one to process
$new = explode('_', $token[1]);
$new = array_map('ucfirst', $new);
$new[0] = lcfirst($new); // for your camelCasing

$new = implode('', $new);
$replace[] = array($token[1], $new);
?>

Next, load each file (you should use RecursiveIteratorIterator with a
RecursiveDirectoryIterator and some kind of filter, probably
RegexIterator, to grab the PHP source files), and then iterate over the
list of variable names somewhat like this:

 $file) {
$source = file_get_contents($path);
foreach ($replace as $items) {

$source = str_replace($items[0], $items[1], $source);

if ($items[0][0] == '$') {
$source = preg_replace('/->(\s*)' . substr($variable, 1) . '/',
   '->\\1'substr($new, 1),
   $source);
}
}
file_put_contents($path, $source);
}
?>

Voila, code refactored.

I trust you know this, but don't run that example code without testing
it on a limited sandbox and comparing the results first :).  I did not
test anything except the regexiterator part to make sure that it
actually grabbed PHP files, the rest is based on my experience
tokenizing for parsing PHP when writing tools like phpDocumentor.

If I made any mistakes, it would be good for you to post your final
scripts for posterity back on here.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php/sqlite3

2009-07-08 Thread Greg Beaver
bruce wrote:
> hi...
> 
> i've got an issue where i'm trying to incorporate sqlite3 into my php.
> 
> i'm running fedora 9, php5.2.9.
> 
> the php app was  installed using the tun install process...
> 
> i know the docs say that php5+ is supposed to have sqlite incorporate
> natively...
> 
> however, on this box, it doesn't! when i do a phpinfo(), i get the pdo
> stuff, but not the sqlite.
> 
> i went ahead and followed a thread on the php.net that walked through adding
> sqlite3, using the phpize, and managed to create the sqlite3.so...
> 
> the phpinfo now has a sqlite section, with a sqlite3.extension_dir that
> points to the dir that contains the sqlite3.so..
> 
> however, when i run a test app using "sqlite_open", i'm getting an error
> saying that the "sqlite_open" is undefined...
> 
> so... my question..
> 
> how the heck can i resolve this issue!

http://php.net/sqlite3.open

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Greg Beaver
Waynn Lue wrote:
> Yeah, that's why I was hoping to maintain a separate install, since it
> would be easier to diff the patches.
>
> Shawn: Thanks for the suggestion to extend, I only wanted to make
> small changes to an existing function though, so it's harder to do it
> that way. My other thought was to refactor the underlying code base to
> make it easier.

Hi Wayne,

If you're only making changes to one function, then you should extend
the class, and override the function.  If the changes are extensive,
then check out the CVS repository, apply your changes, and use the "cvs
diff -u" command to create a patch to send back to the maintainer of the
package.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Editing PEAR packages

2009-07-05 Thread Greg Beaver
Waynn Lue wrote:
> I wanted to makes some local edits to a PEAR package that I downloaded in
> order to build some custom functionality into it.  What's the best way to
> manage this process to ensure that I don't accidentally blow away any
> changes if I update the package?  Should I just copy the entire package to
> my own source repository, then use that directly instead of the PEAR
> package?  And if I do it that way, is there an easy path to upgrade it?

Best would be to follow Shawn's suggestion.  If you do need to make
changes, you should contribute them back to the package, PEAR is an open
public repository, it may be incorporated and help others in your
situation as well (this is the point of PEAR and of open source).

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: namespace keyword

2009-07-02 Thread Greg Beaver
Martin Scotta wrote:
> Hil all
> 
> I'm a 5.2.0 user (WINXP)
> I have a class like this...
> 
> Class IsThisBad
> {
>const NAMESPACE = 'something';
>/* code */
>function __construct( $other=self::NAMESPACE )
>{
>  /* do stuff */
>}
> }
> 
> Recently the version 5.3 was released, so... should I change the const
> "NAMESPACE" in the class? Is it a reserved word?

Yes.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] OCSP DER encoding implemenation?

2009-06-19 Thread Greg Beaver
Hi,

Does anyone have a non-GPLed implementation of DER encoding for an
OpenSSL certificate authority OCSP request floating around, or even a
basic DER encoder?

Thanks,
Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: strange include path error

2007-06-27 Thread Greg Beaver
brian wrote:
> PHP 5.1.4 on Fedora 2
> 
> I recieved a note from a client about a problem with their site today.
> Looking at the error log, i found that the DB connection script that's
> included into any other that needs it was throwing an error because
> MDB2.php couldn't be found:
> 
> Failed opening required 'MDB2.php'
> (include_path='.:/opt/www/zijn2/htdocs/includes:/usr/local/lib/php')
> 
> What's *really* weird is that the paths listed there are
> ancient--everything is in /usr/share/pear now, and the zijn2 one had
> been added--then removed--when i was troubleshooting something (it seems
> like a couple of years ago).
> 
> I checked phpinfo() which shows the correct path.
> 
> # uptime
>  19:41:32 up 282 days, 16:24,  1 user,  load average: 0.13, 0.04, 0.01
> # ls -l /usr/bin/php
> -rwxr-xr-x  1 root root 16466469 Aug 27  2006 /usr/bin/php
> 
> Aug 27, 2006 + 282 days gives June 5, 2007, so it looks like the server
> was rebooted after upgrading.
> 
> Unfortunately, i recieved the mail after my client split for a long
> weekend, and he didn't say what script he was trying to use (the error
> log only points back to the included script, not the original). But a
> quick scan of the site shows no problems at all.
> 
> I also have no .htaccess files for this particular site, and the vhost
> conf checks out. Any idea what the heck just happened here?

Do a grep for "set_include_path" in your client's code - I suspect
you'll find it.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: second/custom PEAR/PECL installation. possible? how?

2007-06-06 Thread Greg Beaver
Eric Butera wrote:

> My work machine is a OS X iMac that has Apple's php4 standard, plus I
> have a php4 and php5 custom compiled myself.  I've been able to issue
> sudo /path/to/php4/bin/pear or /path/to/php5/bin/pear and that
> installs the packages correctly for each version that I want.
> Apparently this practice is completely wrong given that long string of
> commands seen above.

Hi Eric,

For defaults, PEAR relies on a number of constants, including
PHP_SYSCONFDIR and PHP_LIBDIR.  If these are in fact different for php4
and php5, then yes, your PEAR will "just work" without change.

So no, that practice is completely right :)

I had forgotten this is a possibility, so you might just try it out
Jochem and see if it works.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: second/custom PEAR/PECL installation. possible? how?

2007-06-06 Thread Greg Beaver
Jochem Maas wrote:
> I have a [gentoo] server with 2 apache installations ...
> 
> the std distro apache runs with php4 which includes an installation
> of PEAR and PECL.
> 
> the second apache is compiled by hand and runs with php5 (also compiled
> by hand) - obviously both of these are installed somewhere other than
> the default. the [custom] php5 installation does not include PEAR/PECL
> (when I built/installed it I skipped that because I was worried I'd get a 
> conflict
> with the existing PEAR/PECL install and break something).
> 
> I would like to add the APC extension to the php5 setup, normally this is
> as involved as doing the following:
> 
>   > pecl install apc
> 
> only in this case that would install APC in the php4 setup.
> the question is how do I go about getting a second/custom PEAR/PECL setup 
> running
> which I can use with/for the php5 setup. is this even possible? or
> am I stuck with a manual download, compile and install of APC for the
> php5 setup as described here for instance:
> http://carroll.org.uk/archives/2006/02/02/alternative-php-cache-apc-on-debian)?

Hi Jochem,

If you're having PEAR questions, ask on the pear-general list.  It's
pure luck that I happened upon your message, and nobody on php-general
seems to know jack about PEAR.

The solution is quite easy.

You need separate configuration files for PEAR in PHP5.  To get this
going, you should first install a local copy of PEAR for PHP5 only.

Assuming you have PEAR in /usr/local/lib/php, the best choice is to
install another copy in /usr/local/lib/php5:

First you'll need to create a new configuration file, which you can save
as "/etc/pear5.conf".  Your php4 conf will be in /etc/pear.conf.  Then
you need to create a new directory for downloads to avoid conflicts
(easy).  The most important part is to set the php_bin variable to the
path to php5 and finally install your custom copy of PEAR.  I assume you
are using "php5" as the CLI for PHP 5.  Change this to the right name in
`which php5` if I'm wrong.

sudo pear config-create /usr/local/lib/php5 /etc/pear5.conf
sudo pear -c /etc/pear5.conf config-set php_bin `which php5`
sudo pear -c /etc/pear5.conf config-set download_dir /tmp/pear5
mkdir /tmp/pear5
chmod 0777 /tmp/pear5
sudo pear -c /etc/pear5.conf up PEAR

At this point you will have a new pear and pecl executable stored in
/usr/local/lib/php5/pear/.  You'll also want to set the ext_dir to the
location of your extension_dir in php.ini for php5.

sudo pear -c /etc/pear5.conf config-set ext_dir /path/to/php5/ext

Finally, as a convenience, you'll probably want to use ln to make
"pear5" and "pecl5" commands

sudo ln -s /usr/local/lib/php5/pear/pear /usr/local/bin/pear5
sudo ln -s /usr/local/lib/php5/pear/pecl /usr/local/bin/pecl5

Lastly, you will *always* want to call with the -c option

pecl5 install APC

will still use your default configuration file at /etc/pear.conf.

pecl5 -c /etc/pear5.conf install APC

will correctly install and configure APC for php5.

Needless to say, this is more complicated than it seems like it should
be, and the next version of the PEAR installer, Pyrus, makes this
process MUCH easier.  Pyrus has only just been started, and so is barely
past proof-of-concept.

I hope this helps out.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP5 Static functions called through __call() that don't exist... yet

2007-05-19 Thread Greg Beaver
Jared Farrish wrote:
> Hi all,
> 
> I am building an assertType object using static functions. What I want to
> keep away from is the following:
> 
> 
> public static function assertString($para){
>return $answer;
> };
> public static function assertBool($para){
>return $answer;
> };
> ...
> public static function assertArray($para){
>return $answer;
> };
> 
> 
> What I would like to do is replace this with the following:
> 
> 
> if (!class_exists('TypeAssert')) {
>class TypeAssert {
>private static $types = array(
>'array','bool','float','integer','null','numeric',
>'object','resource','scalar','string'
>);
>public static function __call($method,$arguments) {
>$obj = self::assertStandardTypes($arguments[0]);
>return $obj->$method;
>}
>public static function assertStandardTypes($para) {
>$r = TypeAssert::getTypesObject();
>if (is_array($para))$r->array = true;
>if (is_bool($para)) $r->bool = true;
>if (is_float($para))$r->float = true;
>if (is_integer($para))  $r->integer = true;
>if (is_null($para)) $r->null = true;
>if (is_numeric($para))  $r->numeric = true;
>if (is_object($para))   $r->object = true;
>if (is_resource($para)) $r->resource = true;
>if (is_scalar($para))   $r->scalar = true;
>if (is_string($para))   $r->string = true;
>return $r;
>}
>public static function getTypesObject() {
>$obj = (object) '';
>for ($i = 0; $i < count(self::$types); $i++) {
>$obj->{self::$types[$i]} = (bool) false;
>}
>return $obj;
>}
>}
> }
> echo('');
> echo(TypeAssert::string('test'));
> echo('');
> 
> 
> I don't think this is possible (see
> http://marc.info/?l=php-general&m=114558851102060&w=2). But I would LIKE
> for
> it to work (currently, the above code doesn't).
> 
> Anybody have any insight on how I might get this to work?

Hi Jared,

I think you meant to post to php-general, but I can answer your question.

***PLEASE DO NOT REPLY TO PEAR-GENERAL THANK YOU***

You can achieve what you want through this kind of code

$thing = ${"is$thing"}($args[0]);
}
return $test->$method;
}
}
TypeChecker::init()
echo TypeChecker::$singleton->string('test');
?>

However, I don't see any benefit to using static methods here.  Just use
an object.

$thing = ${"is$thing"}($args[0]);
}
return $test->$method;
}
}
$check = new TypeChecker;
echo $check->string('test');
?>

If you're trying to do several assertions and separate them into
classes, do something like so:

type = new TypeChecker;
}
}
$check = new Tester;
echo $check->type->string('test');
?>

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Question

2007-03-20 Thread Greg Beaver
Dan Shirah wrote:
> In my database I have two tables.  One table stores all of the account
> information, the other table stores all of the user information.
>  
> Table 1
> account_id  - is the primary key and is unique to each account
>  
> Table 2
> user_id  - is the primary key and is unique to each user
> account_id  - will be set to whatever the account id is in Table 1
>  
> You are suggesting that when they click "Enter another user for this
> account" that I save the account/user information to the database and
> then when the form refreshes have something like:
>  
> if (!isset($_POST['submit']))
>  
> to determine if this is a continuance of a multiple user submission?
>  
> And then I should select the account_id that was just created?  Using
> something like:
>  
> SELECT scope_identity() FROM accounts
>  
> Or is there a better way to determine the recently created account_id so
> I can use it for any other user data that is created for this account?

Hi Dan,

Yes, there is a better way.  What you have described is probably more
complex than you need, and requires more clicking by the user than is
necessary.

First of all, do you allow multiple accounts for the same user?  If so,
you're going to run into troubles with querying later on with the
current data schema.  Generally, when I'm working with inter-linking
data like you describe, I construct it as:

Table 1 account_info:
account information
account_id

Table 2 user_info:
user information
user_id

Table 3 account_link:
user_id
account_id

This way, you never duplicate user information, and it is very easy to
link or unlink users from accounts.

In the web form, if you allow adding up to 3 users maximum, why not just
put all of the input on a single page?

[html]
Account information:

Form Field 1: 
...

User #1 (required)

Name: _
...

User #2 (optional)

Name: _
...

User #3 (optional)

Name: _
...
[/html]

In addition, you might consider either using an AJAX-based dropdown, or
populating a static dropdown with previous users (assuming the list of
users is short), so that if a previous user is entered into the account,
that name can be used.

In addition, if you have all 3 users on one page, you can validate them
all at once, check for accidental duplicates (i.e. if a name matches an
existing user, bring up the form and ask if they intend to create a new
user, or wish to use the existing one).

There are lots of options.  If you do decide to do a multi-page form,
with database submit right at the last step, there is an example of how
I've done this in the code for pear.php.net's election creation
interface, at
http://cvs.php.net/viewvc.cgi/pearweb/public_html/election/new.php?view=markup.


This code makes use of simple php-based templates found in:

http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step1.tpl.php?view=markup
http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step2.tpl.php?view=markup
http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step3.tpl.php?view=markup

Hope this helps,
Greg
--
Experience the revolution, buy the PEAR Installer Manifesto
http://www.packtpub.com/book/PEAR-installer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: image digit to check password

2007-03-20 Thread Greg Beaver
Alain Roger wrote:
> Hi,
> 
> There is a trend on internet that when you want to change your password,
> you
> need to type :
> 1. the former password.
> 2. the new one
> 3. a 2nd time the new one to confirm that no mistake has been done on step
> 2.
> 
> however, several website also propose an additional security to avoid
> hacking/brute force, they display a 4 digit image with a "random" string
> including number and letters... something like A3P23.
> if user do not respect case and string, password is not changed.
> 
> I would like to know how such system works and if a tutorial exist about
> that ?
> 
> thanks a lot,

http://pear.php.net/Text_CAPTCHA
http://pear.php.net/package/Text_CAPTCHA_Numeral

Regards,
Greg
--
Experience the revolution, buy the PEAR Installer Manifesto
http://www.packtpub.com/book/PEAR-installer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Question

2007-03-20 Thread Greg Beaver
Dan Shirah wrote:
> Looking for some direction here.
> 
> I have a form that collects user data.   When an employee opens the form
> they enter in all of the user data for an account, however the account can
> have multiple users so the employee has the option to "Enter another user
> for this account" and they can do this for as many users as the account
> holds.
> 
> What I can't figure out is how to store the first set of user details, have
> the blank form come up again, store the second set of user details, have
> the
> blank for come up again, insert a third set of details and then have all
> three sets submit to the database at the same time.
> 
> Did the make sense?
> 
> Would using a session work to store all this user data for a single
> submission?

Hi Dan,

Although sessions look appealing, you may find that users use the "Back"
button on their browser to return to the previous step, and sessions
won't allow this to work properly.

If you really wish to wait until the third user before saving any of
them, then I would use hidden form fields with the data from the
previous entries.

However, if I were in your shoes, I would probably set up the form to
create the account and save immediately to the database, then add the
other users one at a time.  The end of a request is the perfect time to
save data, as long as you allow editing of the details.  Again, expect
users to use "Back" and make sure that if you do save using a numeric
primary key, that you pre-generate it so that it will still be present
if the user clicks "Back."  This way, you can safely allow editing of
the data by just using an UPDATE query rather than INSERT if the data
already exists.

Also, if you are taking sensitive data, be sure this web form is either
on a firewalled intranet or some other security precautions so that you
don't expose SSNs to the public hacker community.

Hope this helps,
Greg
--
Experience the revolution, buy the PEAR Installer Manifesto
http://www.packtpub.com/book/PEAR-installer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: unpack on offsets in binary data in variable?

2007-01-09 Thread Greg Beaver
Markus Fischer wrote:
> Hi,
> 
> I'm searching for an efficient way to use unpack on binary data within a
> variable (php 5.1.something). In the past I was doing
> 
> fopen
> fseek
> unpack( fread(...)
> fseek
> etc.
> 
> Now this time I need to do the same, but I don't have an actual file: my
> data is only in a variable and I don't want to operate on a file but the
> variable within.
> 
> I was thinking about using substr() and passing the small chunks of data
> I need to the unpack() function.
> 
> Question: does this work without problems on arbitrary binary, maybe
> containing zero-byte values reliable?

Hi Markus,

This does work fine, but beware of strange behavior with unpack() when
using unsigned types V, N, or L.  I recently was bitten by different
behavior on 32-bit and 64-bit OSes unpacking a large unsigned integer.
If you need unsigned, use sprintf("%u", $whatever) to get the actual
integer.

substr() works nicely on strings for unpack(), see how PHP_Archive uses
it in http://cvs.php.net/viewvc.cgi/pear/PHP_Archive/Archive.php .  If
you are writing for forward compatibility with PHP 6's unicode and plan
to accept input from a variety of sources, you may want to cast the
string to binary type.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: call_user_func_array on STATIC method

2006-08-18 Thread Greg Beaver
steve wrote:
> Does anyone know of a way to call a static method with an array of objects?
> 
> I thought for sure this would work, but it does not:
> 
> $v = call_user_func_array("$class::$method",$params);
> 
> Do I have to resort to eval()???

$v = call_user_func_array(array($class, $method), $params);

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RELEASE ANNOUNCEMENT: PhpDocumentor 1.3.0 *stable*

2006-08-18 Thread Greg Beaver
RELEASE ANNOUNCEMENT
PhpDocumentor 1.3.0 *stable*
August 18, 2006
Download:
pear upgrade PhpDocumentor
http://pear.php.net/PhpDocumentor
http://sourceforge.net/project/showfiles.php?group_id=11194&package_id=10450&release_id=440432
Information and documentation:
http://www.phpdoc.org


The PhpDocumentor team would like to announce the release of
PhpDocumentor version 1.3.0.  This is the first stable release since
2003, and marks a dramatic step up from previous releases.

This release adds in:
 - full PHP 5 support, including knowledge of internal classes
   for PHP version 5.1.0+ using the Reflection extension.
 - highlighting of tutorial XML
 - beautifying of output from the XML:DocBook/peardoc2:default
   converter

In addition, the release fixes more than 100 bugs found since version
1.2.3.  Output from source highlighting is much more efficient,
resulting in slightly smaller file size for option sourcecode=on.
Multi-national characters are now allowed in a package name, although
internationalization support is not fully complete.

PhpDocumentor is the standard automatic documentation solution for PHP
written in PHP.  Originally inspired by JavaDoc, PhpDocumentor has over
6 years of battle-testing and is bundled in popular IDEs such as Zend
Studio, PHPEdit, PhpEd, and others.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: SPL Iterator and Associative Array

2006-06-02 Thread Greg Beaver
Jason Karns wrote:
> I'm going to try my best to explain what I'm trying to do.
> 
> I have my own class that has an array member.  This class itself implements
> Iterator.  One of the fields in the array is itself an array that I would
> like to iterate over. Here's some code:
> 
> class Folio implements Iterator {
> $projects = array(
>   array(
>   'title'=>"",
>   'clip'=>"",
>   'small'=>array('1','2','3')),
>   array(
>   'title'=>"",
>   'clip'=>"",
>   'small'=>array('0','1','2'))
> );
> function title($x){
>   return current($this->projects[$]['small']);
  ^^
> }
> 
> function smalls($x){
>   return $this->projects[$x]['small'];
> }
> }


Hi Jason,

The code you pasted is littered with fatal errors and bugs (I marked one
example with "^^" above).  Please paste a real batch of code that you've
tested and reproduces the error and that will be much more helpful.  The
PHP version would be helpful to know as well.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Getting an advanced foreach to work

2006-05-23 Thread Greg Beaver
Chris wrote:
> Jonas Rosling wrote:
> 
> ...
> 
>> while ($count < count($salespersons)) {
> 
> 
> I see you have solved it - just one comment.
> 
> This particular line will get evaluated every time. If you have a large
> number of elements in $salespersons, it will slow things down considerably.

Quick amendment to this statement: PHP stores the number of elements in
a userspace array directly in the internal zval, so calling count()
simply reads that value no matter how big the array is (in algorithmic
terms, it is O(1)).  In other words, count(array(1)) is every bit as
efficient as count(array_pad(array(1), 100, 1)) if you eliminate the
cost of creating the 100 element array.

Having said this, there is potentially significant overhead involved in
calling a function as opposed to a variable lookup, and so you might end
up saving a few microseconds.  However, because count() is O(1), it will
be a constant amount per loop.  If you need to eke out that much extra
performance, you may be better off using a profiler to see where the
real bottlenecks in the code are.

Greg

> 
> From a performance point of view you're much better off doing:
> 
> $sales_count = count($salespersons);
> 
> while($count < $sales_count) {
> 
> 
> The only reason to leave the count in the while statement is if you are
> adding/removing to that array within the loop, otherwise chuck it in a
> temp variable and use that instead.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Extensions Directory (PEAR/PECL)

2006-05-22 Thread Greg Beaver
Robert Samuel White wrote:
> Please let me know if this would be more appropriate to post in a PEAR or
> PECL forum.  Today, I've been trying to install some extensions - in
> particular, the GD library and the ZIP library.  I've finally managed to get
> it all working, but there was one issue that I'd like to clear up for future
> reference if possible.
> 
> When I ran the command:
> 
> pecl install zip-1.3.1
> 
> It intalled the zip.so file to:
> 
> /usr/local/lib/php/extensions/no-debug-non-zts-20050922/zip.so
> 
> The only way I could get zip support working was to put it here:
> 
> /usr/local/php/ext
> 
> Which is where my extensions directory is located.
> 
> I've checked, and the extensions directory is set correctly in the php.ini
> file.
> 
> Does anyone know where/how it would come up with this other path?

Hello Robert,

If you wish to receive the best advice for PEAR questions, ask on
[EMAIL PROTECTED], and for PECL questions (questions that have
to do with the internals of the extension, compilation problems, etc.)
ask on [EMAIL PROTECTED]

This problem is easily solved:

pecl config-set ext_dir /usr/local/php/ext

voila.  No need to futz with php.ini or copy the extension (a bad idea -
you have to remember that you did this when you decide to upgrade or
uninstall)

PEAR uses its own configuration file which is independent of php.ini.
Why?  You can use the same PEAR extensions in command-line code and for
web applications.  These often have completely different php.ini
settings for obvious reasons (no need for apache-specific stuff inside
the command-line php).

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] [RELEASE ANNOUNCEMENT] phpDocumentor 1.3.0RC6

2006-05-02 Thread Greg Beaver
May 2, 2006
RELEASE ANNOUNCEMENT
phpDocumentor 1.3.0RC6
Download:
http://pear.php.net/PhpDocumentor
http://www.phpdoc.org

The phpDocumentor team would like to announce the release of version
1.3.0RC6.  This is the last release candidate of version 1.3.0, the
first stable version to be released since 2004.  The 1.3.0 series is a
milestone, and 1.3.0RC6 demonstrates that amply.

phpDocumentor is written by Gregory Beaver, Joshua Eichorn and others in
PHP, and works by parsing PHP source code, and generating customizable
documentation in HTML, PDF or windows help file formats.  phpDocumentor
is the premiere auto-documenting application for PHP.  Used by giants of
the industry such as Zend, ez Systems, and the standard auto-documentor
of PEAR, the program is also bundled in popular IDEs such as Zend
Development Environment, PHPEdit, and nuSphere phpEd.

In version 1.3.0RC6, not only is stability at its highest level yet, but
full support for PHP5 features has been implemented, including:

 - documenting classes that extend internal classes (like Exception) or
implement internal interfaces using the Reflection extension.
 - userspace interfaces, abstract classes
 - access control (private/protected/public)
 - access modifiers (final/abstract/static)
 - class and array type hints

To acquire phpDocumentor, either run:

pear upgrade PhpDocumentor-beta

or download your copy from www.phpdoc.org and extract, following
instructions in the INSTALL file.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How does PECL and PEAR handle versioning of PHP core?

2006-04-26 Thread Greg Beaver
D. Dante Lorenso wrote:
> All,
> 
> If I install PHP 5 and want to use a PECL extension, does that work the
> same as if I install PHP 4 and try to use the same extension?
> 
> One extension that I use a lot is 'memcache' from PECL:
> 
>http://pecl.php.net/package/memcache
> 
> When I view this site, I do not see any reference to the version of PHP
> which is required.  Does it matter about PHP 5.0.5 vs PHP 5.1.2 etc? 
> Can someone explain how PECL or PEAR works in order to distribute only
> compatible versions of code?

The extension uses dependencies - most extensions compile without
modification for multiple PHP versions.  Those that require some
finagling actually do so through package.xml or configure tricks
(usually configure tricks).

You do need to compile and install a separate extension for each php version


Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Ajax please....

2006-04-08 Thread Greg Beaver
Robert Cummings wrote:
> On Sat, 2006-04-08 at 14:40, Manuel Lemos wrote:
> 
>>Hello,
>>
>>on 04/08/2006 10:53 AM Ryan A said the following:
>>
>>>Carlin Bingham / Tedd:
>>>---
>>>Yes, but then I would have to reload the whole page just to tell the person
>>>that the account username was already taken...thats how its "traditionally"
>>>done...but I want to try doing it without reloading the whole page...hence
>>>Asynchronous JavaScript And XML (AJAX) although the XML part at the end is
>>>not really too accurate because from what I see you can (and i have) use
>>>AJAX without any XML...in my case it would be AJAH or AJAT (H=HTML, T=TEXT)
>>>:-p
>>
>>There is a misunderstanding here. The X does not necessarily means
>>generic XML. It may mean XHTML. Anyway, an AJAX request may server any
>>type of data.
>>
>>Another point is that AJAX does not mean necessarily using
>>XMLHttpRequest objects . As you may read in the Wikipedia definition,
>>many AJAX frameworks use IFrame.
>>
>>[-- SNIP PIMPING OF IFRAMES --]
> 
> 
> I'm probably just having a bowel movement or something, but I think
> going with a lib that supports either iframe or xmlhttprequest
> interchangeably is probably the way to go. While iframe may have more
> features and less instability surrounding it right now, you can probably
> bet your ass, xmlhttprequest is going to become the standard for the
> simple reason that it's purpose was to do this kind of thing, whereas
> iframes are a dirty little hack :)
> 
> I would just hate to have to rewrite everything once iframes start
> sucking. And no, I don't currently know of an ajax lib that does this,
> but I'll certainly be making mine do so in the near future :)

HTML_AJAX (http://pear.php.net/HTML_AJAX) has had iframe fallback
support since I first checked it out in version  0.2.0

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP AJAX Framework - Suggestions Please

2006-04-01 Thread Greg Beaver
Andrei Verovski (aka MacGuru) wrote:
> Hi,
> 
> Anyone can suggest me which PHP AJAX framework you are using, for what 
> reason(s), what are pros and cons of your particular choice.
> 
> I found many, and now facing difficult choice.
> 
> BTW, how do you pass session id between calls to PHP from JavaScript (cookies 
> or explicit foo.php?PHPSESSSIONID=blahblahblah)?
> 
> Thanks in advance for any suggestion(s).

http://pear.php.net/HTML_AJAX

The setup is simple, usage is very easy to debug and it is actively
maintained by one of the more respected PHP coders, Josh Eichorn.

Cookies are fully supported and are preferrable to using a GET variable.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

> Just for argument's sake: the result is not identical.  Assume, for
> one second, that you have two PHP functions:
>
> function getCitiesAsHTML($countryName);
> function getCitiesAsXML($countryName);
>
> The first issues a snippet of HTML text, with s.  The second
> issues a serialized XML document.
> The first one is engineered to be used with innerHTML.  The second one
> is engineered to be processed by the client so it can do any generic
> transformation.
>
> Which one do you think has the greatest potential for reusability in
> your JS client code?  Option 1 or Option 2?
>
> 
>
> Okay, this is the end of the discussion for me.  You're stating a
> bunch of crap which does not correlate with modern accepted software
> quality practices.  You're conveniently ignoring that server-side
> errors and TCP connection errors are out there, and while they may be
> only 2% of all traffic, you need your JS application to work 100% of
> the time or give reasonable feedback as to why it cannot work.  You're
> grossly oversimplifying matters to prove your point, which flies right
> in the face of orderly, neat, structured, standards-based software
> development.

Manuel,

Your insults are not exactly convincing arguments for your case :).  If
you had even taken 1 second to investigate http://pear.php.net/HTML_AJAX
you would know that your arguments about TCP and server-side errors are
irrelevant.  Why?  I'll tell you why!

In fact, to make things easier, I will quote myself from previous
messages.  Consider this current email to be Message #4.  From Message #2:

"2) HTTP 500?

This should be handled internally by the ajax mechanism (HTML_AJAX does
handle this)"

To rephrase what I said above, HTML_AJAX handles server-side and TCP
connection errors.  I neglected to say exactly how it does so in the
message, perhaps that is the confusion.  Upon a timeout or other error,
a javascript alert() is used.  Upon a server-side error (a PHP error in
the server-side script), by default a javascript alert() is raised with
the contents of the PHP error complete with backtrace - very handy for
debugging.

So, that kills straw man argument number one, which I will quote again
for clarity: "You're conveniently ignoring that server-side errors and
TCP connection errors are out there, and while they may be only 2% of
all traffic..."

As we can see, this statement is untrue.  So, moving on:

HTML_AJAX is designed such that you register classes that simply return
regular old PHP values, and it then serializes them into JSON or any of
a number of choices (as I have said, let me quote myself from Message #1:

"I use http://pear.php.net/HTML_AJAX for the actual ajax details, and it
has several serialization options, JSON by default.")

The fact is, your example php functions miss the point by returning HTML
vs. XML.  The return value of my functions are *strings* which are then
serialized into JSON by HTML_AJAX.  If you need to do client-side
transformation, that's not a problem, as contrary to a previous post,
HTML inserted via assignment to innerHTML *is* accessible via DOM,
otherwise getElementById() wouldn't work on the .  To prove
this, you can look in Firefox's DOM inspector.  After loading HTML
inserted via innerHTML, at first it will not show any changes, but by
closing the DOM inspector and re-opening it, it will refresh with the
current page value, and all of the new innerHTMLed HTML will show up.

Also, let's remember back to the original question from Daevid Vincent,
which was (and I quote):

"I need to dynamically update a select box with results from a SQL
database using AJAX, but I can't find a single example of how to do this."

A select box is not a need to do client-side manipulation.  It is a
select box.  Should you need to re-format the data in another format,
there are several options which all boil down to one of:

1) re-factor so that you don't need to re-format on the client side (my
personal favorite)
2) return another format such as an array and manipulate the data on the
client-side

However, it is not useful to talk about some generic time down the road
- what is important is to design your application so that it is easy to
change it.  If you have a whole bunch of complicated client-side logic,
this makes it more difficult to re-factor.  After all, only one of two
things are certain in programming:

You *will* have to refactor that code in the future, or you will quit. 
Whichever comes first.

So, straw man argument #2: "You're grossly oversimplifying matters to
prove your point, which flies right in the face of orderly, neat,
structured, standards-based software development."

is simply insulting :).  I was posting *actual* javascript code from a
well-working application with only the function names changed.  Want the
original code as written?  Here you go:

var addressesCallback = {
searchAddressesGetHTMLOptions: function(res) {
   document.getElementB

Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

>
>> 1) what if the returned markup is invalid?
>>
>> Well, the browser renders it oddly, and through the fact that your
>> server-side code is straightforward filling in an html template with
>> actual values, all you need to do is view the source (with the firefox
>> web debugging extension you can view generated source) or to add an
>> "alert(res)" in there.
>>  
>>
> Now, how do you automate that in a testing suite?

This is obvious: you need only test the output of the PHP server class,
which is quite simple, as none of the complexity lies in the
javascript.  As long as your ajax javascript is testable for its ability
to work (and HTML_AJAX is), then you are covered.  In other words, the
need to test the javascript end is simply unnecessary.  All you need to
do is to test that the javascript actually properly initiates the ajax
call.  In my case, it involves these lines:

var someCallback = {
doThis: function(res) {
   document.getElementById('blah').innerHTML = res;
}
}

function doThisThing(fragment)
{
var c = new backendclass(someCallback);
c.doThis(fragment);
}

Obviously, this is simply not complicated enough to warrant extensive
testing of the interface between the javascript -> HTML_AJAX -> php code
and back.  All we need to test is the HTML_AJAX component, and the PHP code.

>   Going beyond, how do you set up unit (or other types of) tests in a
> cheap, straightforward way?  How do you assure quality of an
> application built like this?

In order to unit test the javascript, you would need to do the same
stuff that is done for DOM, but it would be far simpler to set up.  I've
already answered the PHP end.

>
>> 3) tag soup?
>>
>> I hardly think a  tag qualifies as "tag soup" but "tag soup" is
>> of course a non-definite term anyways :).
>>  
>>
> Well, returning an JSON or XML document certainly is more structured
> than using a simple SELECT and several OPTION HTML tags.  The point
> here is, precisely, decoupling implementation from interface.

What I think is *still* unclear is that the difference between what you
are suggesting and what is actually working on my website is this:

Your solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a text file
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code parses the text file to grab option/value combinations
6) javascript code creates each option node, and adds the value/text
7) javascript code creates the select node, adds each option
8) javascript code adds the select to the document

My solution:

1) PHP code generates the data from the fragment
2) PHP code converts the data into a string containing the
 tags
3) PHP code serializes it to JSON
4) javascript code unserializes the JSON
5) javascript code sets the innerHTML to the new select

In your solution, you need to test steps 1, 2, 5, 6 and 7.  In addition,
steps 2, 5, 6, and 7 all require testing in javascript (and time) to
guarantee that you get the result (8).

In my solution, you need to test step 1 and 2 to ensure that bounds are
satisfied and that a proper  tag is always generated, and this
only needs to be done in PHP.  Both cases assume you don't need to test
the ajax mechanism itself.

In short, it's just not worth the trouble to triple the number of
necessary tests when the result is identical, and it is actually
*easier* to see what HTML you're going to end up with from the PHP code.

> Sure, your solution mostly works.  But what I still wonder is, is it
> the best solution in terms of software quality? 

I think I've made my opinion sufficiently clear on this point.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:
> Greg Beaver wrote:
> 
>> This is far too complicated.  You don't need 50 lines of code to convert
>> from server-side data to HTML when the browser does it for you (and far
>> more efficiently) with this code:
>>
>> var someCallback = {
>>ajaxfunc: function(res) {
>>   document.getElementById('blah').innerHTML = res;
>>}
>> }
>>  
>>
> You know you're oversimplifying matters.  What if the returned markup is
> invalid?  What if the server experienced an HTTP 500 error?  Why should
> anyone want to program their application to return 'tag soup' instead of
> formally defining interfaces via standards?  That's asking for
> maintenance nightmares.

1) what if the returned markup is invalid?

Well, the browser renders it oddly, and through the fact that your
server-side code is straightforward filling in an html template with
actual values, all you need to do is view the source (with the firefox
web debugging extension you can view generated source) or to add an
"alert(res)" in there.

2) HTTP 500?

This should be handled internally by the ajax mechanism (HTML_AJAX does
handle this)

3) tag soup?

I hardly think a  tag qualifies as "tag soup" but "tag soup" is
of course a non-definite term anyways :).

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Manuel Amador (Rudd-O) wrote:

> Greg Beaver wrote:
>
>> Daevid Vincent wrote:
>>  
>>
>>> I need to dynamically update a select box with results from a SQL
>>> database using AJAX, but I can't find a single example of how to do
>>> this.
>>>
>>> Basically I have a text input field, and a select box. As someone
>>> types in the input field, I want the select box to fill in the
>>> results of matches.
>>>
>>> I can fill in a  (as per the ten million examples out there)
>>> and that's all fine and dandy, but way too simplistic for what I need.
>>>   
>>
>>
>> The best way to do this is indeed to put the entire select in a div, and
>> to replace the innerHTML of that div with the html for the select.
>>  
>>
> But that is not DOM.  Another way to do this is:

It's also not Java or Fortran, but as with these argument, that is
irrelevant information - it is valid javascript, and as we all know, the
"J" in ajax ain't DOM, it's javascript.

> - run your XMLHttpRequest
> - have your server-side AJAX target script spit a newline-separated
> text file, with IDs and names such as:
> 1 XYZ
> 2 JWV
> 3 Something
> - once the response is on the client, break the text file down with
> string manipulation functions/methods (split() comes to mind), perform
> a document.getElementByID("yourselect") and append
> document.createElement("option")'s to it, obviously setting the value
> properties on each element, and appending a
> document.createTextNode("your option text") into every option you create.

This is far too complicated.  You don't need 50 lines of code to convert
from server-side data to HTML when the browser does it for you (and far
more efficiently) with this code:

var someCallback = {
ajaxfunc: function(res) {
   document.getElementById('blah').innerHTML = res;
}
}

>
>> Always do as much processing as possible on the server side, or your
>> application will become interminably slow both to load and to run.
>>
>> In my testing, I've found that the latency over high speed internet of
>> passing the entire select is exactly the same as it is from my local
>> machine.  When I used to pass an array of data and repopulate using
>> javascript DOM, it was slow as molasses, and I would occasionally have
>> weird timeouts.
>>  
>>
> It shouldn't have been slow.  DOM manipulation is fast.  But you need
> to remember to instantiate new objects, add children objects first (in
> the example, the text nodes and options), and add the parent objects
> to your document then.  Otherwise, I can see how your application
> could get slow.

I hate to burst your bubble, but I am an experienced developer, and do
know how to use DOM.  My application used these exact techniques, and
was simply slower.  The internal rendering code for a browser is just
simply far faster than javascript DOM will ever be.

Another truth is self-evident: all browsers have uniformly implemented
the setting of innerHTML for far longer than the implementation of DOM
has been uniform, and your chances of encountering a bug in a particular
browser implementation are much slimmer.

>
>> Don't try to be smart when you can be simple :)
>>
> I'd advise against this, and I'd also advise you to look up a
> JavaScript-usable serialization microformat for data coming from the
> server (XML is kind of unwieldy for this).  Look for JSON on google. 

You advise against simplicity?

First off, any good programmer will tell you that simplicity is always
the first thing to look for in an application, as complex algorithms are
almost always best implemented with simple (and clever) code, but this
is a tirade for another time.  Second, what makes you think I don't
transfer the HTML using JSON?

I use http://pear.php.net/HTML_AJAX for the actual ajax details, and it
has several serialization options, JSON by default.

First off, let's examine why one would use ajax in the first place. 
It's not to be "correct" or rigorous - it is to streamline the user
experience.  Ajax of course introduces other concerns such as the danger
of overloading the server with more HTTP requests than traditional apps,
but this is easily fixed by ensuring that examples like the "type in
text box and populate select" have some appropriate limits on how often
it actually sends the requests for data.

If you still don't believe me, take a straw poll of the most proficient
programmers to see how they are using ajax in real-world time-critical
applications.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP, SQL, AJAX, JS and populating a SelectBox?

2006-03-18 Thread Greg Beaver
Daevid Vincent wrote:
> I need to dynamically update a select box 
> with results from a SQL database using AJAX, 
> but I can't find a single example of how to do this.
> 
> Basically I have a text input field, and a select box. 
> As someone types in the input field, 
> I want the select box to fill in the results of matches.
> 
> I can fill in a  (as per the ten million examples out there)
> and that's all fine and dandy, but way too simplistic for what I need.

The best way to do this is indeed to put the entire select in a div, and
to replace the innerHTML of that div with the html for the select.
Always do as much processing as possible on the server side, or your
application will become interminably slow both to load and to run.

In my testing, I've found that the latency over high speed internet of
passing the entire select is exactly the same as it is from my local
machine.  When I used to pass an array of data and repopulate using
javascript DOM, it was slow as molasses, and I would occasionally have
weird timeouts.

Don't try to be smart when you can be simple :)

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php -w causes a parse error

2006-01-25 Thread Greg Beaver
Bom Demais wrote:
> I wanted to run "php -w" on my include files on the live server to reduce
> overhead.  But php -w causes parse errors in the include files.  Here's an
> example of what happens:
> 
> tanner /php_files
> % php -l misc.inc
> No syntax errors detected in misc.inc
> tanner /php_files
> % php -w misc.inc > misc.stripped.inc
> tanner /php_files
> % php -l misc.stripped.inc
> PHP Parse error:  parse error, unexpected '&', expecting ']' in
> misc.stripped.inc on line 2
> 
> Parse error: parse error, unexpected '&', expecting ']' in misc.stripped.inc
> on line 2
> Errors parsing misc.stripped.inc
> 
> 
> Of course i try to look at line 2 to see what the error is, but now the
> whole file is on line 2, so there's no way to know what's breaking!
> 
> please let me know if you have any suggestions.

My suggestion: don't try to reduce overhead by eliminating whitespace.
Take two approaches instead:

1) try to optimize by simplifying how your website does things (don't
use 30 objects and a 4000-line script just to display a template)
2) try to optimize database use (only use it where necessary, and
optimize queries) and optimize page generation by using a cache if necessary
3) ask your host provider to install a bytecode cache like Zend
Optimizer or APC.

If they have installed one already, your best efforts with php -w will
result in identical running times, and as you noted, make it impossible
to debug any problems.

Best of luck,
Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Local PEAR install confusion

2005-11-20 Thread Greg Beaver

Colin Andrews wrote:

Thanks a ton-

So then that means that the only way to get rid of the warnings is to 
change the

error reporting level?


No, report the warnings as a bug at pear.php.net/bugs

You can also hand-fix the source in the mean time, it's only 5-10 lines 
of code, right?


Greg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Local PEAR install confusion

2005-11-20 Thread Greg Beaver

Colin Andrews wrote:

about 3 months ago I set up a local install of pear on my web host account (a
cpanel system).

A couple days ago, my hosting company upgraded us to php 4.4.2-dev. I started
seeing a lot of warnings coming out my PEAR includes:
"Notice: Only variable references should be returned by reference in
/home/headbonk/pear/lib/DB.php on line 1132" and other similar ones.

So I figured maybe PEAR needs an upgrade to go with the php upgrade.

I did pear upgrade-all and that seemed to fix some of the warnings - not sure I
didn't keep track of exactly which modules were giving warnings.

I also go a couple messages from the pear installer that I didn't understand:
Failed to download pear/Archive_Tar (recommended version 1.3.1), latest release
is version 1.3.2, stability "stable", use
"channel://pear.php.net/Archive_Tar-1.3.2" to install
/tmp/glibctestqGYBFW:1:22: features.h: No such file or directory
pear/PEAR dependency package "pear/Archive_Tar" installed version 1.3.2 is not
the recommended version 1.3.1, but may be compatible, use --force to install

I started poking around, and found that pear -V reports my PHP version # as
4.3.10. phpinfo() in my document root reports the php version as 4.4.2-dev.

My gut is just to redo the local install from scratch, but I don't know if
there's something I need to worry about going on. I could just set a higher
error reporting level in my .htaccess file.

Any suggestions? Enlightenment?


Hi Colin,

Your setup sounds just fine to me.

The "features.h" message is a bug in PEAR 1.4.4 that is fixed in PEAR 
1.4.5 that will be released any day now, and Archive_Tar is a brand new 
version, so automatic upgrade is disallowed until it can be tested in 
the wild.  THis is because if it were to break PEAR, this would make it 
difficult to grab any packages.  Hwoever, if you would like, upgrading 
via "pear upgrade --loose Archive_Tar" should work, or "pear upgrade 
--force Archive_Tar"


You do not need to re-install from scratch.  Your host has an older CLI 
version of PHP than the PHP version used by apache.


Greg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex for Amateur Radio Callsigns

2005-11-17 Thread Greg Beaver

Leonard Burton wrote:

HI,



Tuesday, November 15, 2005, 8:39:19 PM, you wrote:


Here are how they look
W1W
W1AW
WA1W
AD4HZ
N9URK
WB6NOA
4N1UBG


Let's do it this way... What are the rules for a valid callsign?



Basicly, you see an example of each different type of callsign.  Other
than the patterns you  see above there are no real rules.  A letter in
the example above means that there can only be a letter in the spot
and a number in a spot means there can only be a number in that spot. 
There are 7 different formats and you see the one above.


Did you see the regex I had in a previous post?


/^([A-Z]{1,2}|[0-9][A-Z])([0-9])([A-Z]{1,3})$/

Using preg_match(), this will split a callsign like N8LAI into

array(
 0 => 'N8LAI',
 1 => 'N',
 2 => '8',
 3 => 'LAI'
)

and you can use the information however you like (i.e. this is a 
standard technician/general class call sign, located in region 8 
Michigan/Ohio/Kentucky, etc.)


_... .
Greg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] [RELEASE ANNOUNCEMENT] PEAR 1.4.0 provides revolution in PHP installation

2005-09-20 Thread Greg Beaver
September 20, 2005
FOR IMMEDIATE RELEASE
Contact: Gregory Beaver ([EMAIL PROTECTED])

As of Sunday, September 18, 2005, the PEAR installer has reached
maturity as an enterprise-level installation tool for PHP code.  The
release of version 1.4.0 stable ushers in several essential features for
management of PHP extensions and packages.

1.  PEAR channels
(http://pear.php.net/manual/en/guide.migrating.channels.php)
2.  Better handling of PECL extensions and dependencies on PECL packages
(http://pear.php.net/manual/en/guide.developers.package2.peclinfo.php)
(http://pear.php.net/manual/en/guide.developers.package2.dependencies.php)
3.  more than 650 regression tests in .phpt format
4.  extensive application support through addition of post-install
scripts, custom file roles and file tasks, and the new bundle package
type (http://pear.php.net/manual/en/guide-migrating.php)

PEAR Channels provide a unique distributed installation paradigm.  By
distributing packages through a channel, users can install and configure
an application with a single step rather than the old
download/unzip/tinker system.  For instance, if a high-quality package
is written that is licensed under the GNU license, it cannot be
distributed through pear.php.net or pecl.php.net.  Now, it is possible
to set up a channel like the hypothetical "pear.example.com" and
distribute it that way.  The user can then install this package just
like any other with:

$ pear install pear.example.com/Packagename

Better yet, developers can depend on this package in their own packages,
removing the need to bundle dependencies.  Critical security fixes for
dependencies can be quickly updated without requiring a release for the
main application.

For PHP extensions written in C/C++, the new "pecl" command provides a
more robust way to install and upgrade PECL packages.  In addition, for
PECL developers, several enhancements to the way dependencies work allow
the PEAR installer to properly detect a PECL extension regardless of
whether it was built into PHP, a shared module, or installed via the
"pecl" command.

All of these new features come with additional stability, thanks to the
use of over 650 .phpt-based regression tests.  In the development of
PEAR 1.4.0, several low-level design flaws were uncovered in PEAR 1.3.6
and earlier that have all been fixed in version 1.4.0.  All new features
have been rigorously tested both through regression tests and in the
wild with an extensive alpha- and beta-testing period that covered
nearly a year.

The PEAR installer now has far greater application support.  The
addition of post-installation scripts allows standardized customization
of packages.  Custom file roles and file tasks allow granular
configuration of packages at the file level.  In addition, distribution
of large applications can be simplified with the new "bundle" package
type.  Bundles allow distributing a package and all of its dependencies
in a single file.

PEAR (http://pear.php.net) is the official code repository of the PHP
project (http://www.php.net).  In addition to providing the PEAR
installer, PEAR provides high-quality object-oriented libraries through
pear.php.net, and PHP extensions through pecl.php.net.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] [RELEASE ANNOUNCEMENT] PEAR 1.4.0 provides revolution in PHP installation

2005-09-20 Thread Greg Beaver
September 20, 2005
FOR IMMEDIATE RELEASE
Contact: Gregory Beaver ([EMAIL PROTECTED])

As of Sunday, September 18, 2005, the PEAR installer has reached
maturity as an enterprise-level installation tool for PHP code.  The
release of version 1.4.0 stable ushers in several essential features for
management of PHP extensions and packages.

1.  PEAR channels
(http://pear.php.net/manual/en/guide.migrating.channels.php)
2.  Better handling of PECL extensions and dependencies on PECL packages
(http://pear.php.net/manual/en/guide.developers.package2.peclinfo.php)
(http://pear.php.net/manual/en/guide.developers.package2.dependencies.php)
3.  more than 650 regression tests in .phpt format
4.  extensive application support through addition of post-install
scripts, custom file roles and file tasks, and the new bundle package
type (http://pear.php.net/manual/en/guide-migrating.php)

PEAR Channels provide a unique distributed installation paradigm.  By
distributing packages through a channel, users can install and configure
an application with a single step rather than the old
download/unzip/tinker system.  For instance, if a high-quality package
is written that is licensed under the GNU license, it cannot be
distributed through pear.php.net or pecl.php.net.  Now, it is possible
to set up a channel like the hypothetical "pear.example.com" and
distribute it that way.  The user can then install this package just
like any other with:

$ pear install pear.example.com/Packagename

Better yet, developers can depend on this package in their own packages,
removing the need to bundle dependencies.  Critical security fixes for
dependencies can be quickly updated without requiring a release for the
main application.

For PHP extensions written in C/C++, the new "pecl" command provides a
more robust way to install and upgrade PECL packages.  In addition, for
PECL developers, several enhancements to the way dependencies work allow
the PEAR installer to properly detect a PECL extension regardless of
whether it was built into PHP, a shared module, or installed via the
"pecl" command.

All of these new features come with additional stability, thanks to the
use of over 650 .phpt-based regression tests.  In the development of
PEAR 1.4.0, several low-level design flaws were uncovered in PEAR 1.3.6
and earlier that have all been fixed in version 1.4.0.  All new features
have been rigorously tested both through regression tests and in the
wild with an extensive alpha- and beta-testing period that covered
nearly a year.

The PEAR installer now has far greater application support.  The
addition of post-installation scripts allows standardized customization
of packages.  Custom file roles and file tasks allow granular
configuration of packages at the file level.  In addition, distribution
of large applications can be simplified with the new "bundle" package
type.  Bundles allow distributing a package and all of its dependencies
in a single file.

PEAR (http://pear.php.net) is the official code repository of the PHP
project (http://www.php.net).  In addition to providing the PEAR
installer, PEAR provides high-quality object-oriented libraries through
pear.php.net, and PHP extensions through pecl.php.net.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Objects and Performance

2005-06-08 Thread Greg Beaver
Greg Donald wrote:
> On 6/8/05, NSK <[EMAIL PROTECTED]> wrote:
> 
>>Hi, I am creating a small API in PHP, i.e. a collection of reusable functions
>>for other programmers. As it is now, it is just many functions together in
>>the same file. Do you think I should make it object-oriented? What are the
>>pros and cons of this approach in PHP?
>>
>>I am particularly very concerned about performance. Are object methods slower
>>than functions in php?
> 
> 
> Definitely not scientific but have a look:
> http://destiney.com/Benchmarks

If you want to compare object methods versus functions, you should
compare identical code inside a method to code inside a function.
Greg's benchmarks compare two different ideological code structures.
Quite honestly, the wrapping of mt_srand() inside a function or method
does not satisfy the definition of good coding, object-oriented or
otherwise.

Functions/methods should be used to abstract common operations.
mt_srand() already does this necessary abstraction, and putting a
further wrapper around it makes no sense.

Nobody can give you a good answer to your question without seeing the
specific code.  If your code requires a lot of global variables in order
to operate, you might consider abstracting this into a class.  Also, if
you find yourself creating several copies of the same variables, use
classes in order to allow two incarnations of the code to exist in the
same file as objects.

If your code does simple operations on a few operands and returns a
value, like our mt_srand() function, there is absolutely no point in
making it more complicated.

However, you could consider wrapping the functions inside a class and
using them as static methods.  This would essentially give them a
"namespace" that would allow any conflicts with other programmer's
function names to be more easily resolved.  In other words, renaming a
class is a whole lot simpler than renaming a function (think
search-and-replace "ClassName::" versus "functionprefix_" - the second
one might inadvertantly replace variables, etc., but the first is
unusual syntax)

So, in short, analyze the problems your code solves, and see if they
would be better solved by abstracting into classes, or by keeping the
code as functions.  Forget about minor performance differences from
program syntax unless you're writing code for a site with thousands of
hits per second.  In that case, you'll want to use a profiler like APD
to find the real bottlenecks in your code.  Otherwise your main
inefficiency is going to be programmer time rather than processor time:
make the code readable and maintainable and it will cut down on bugs and
work better than "faster" code.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PEAR installation

2005-06-08 Thread Greg Beaver
Danielle wrote:
> I'm having problems installing PEAR.
> When running the go-pear.php installer (version 0.2.2), I get the following
> message after submitting the form on the 'Configuration' page...
> 
> Error
> 
> Downloading package: Pager
> 
> download of http://pear.php.net/get/Pager failed: A connection attempt
> failed because the connected party did not properly respond after a period
> of time, or established connection failed because connected host has failed
> to respond.
> (10060)

You had an internet timeout.  Make sure that any proxy configuration is
entered, or if you don't use one, try again later and it should work.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: 4.3.11 and PEAR

2005-04-06 Thread Greg Beaver
Jakob Goldbach wrote:
> Hi,
> 
> What happened to all the pear packages that were in 4.3.10 ?
> 
> I don't see this change in the changelog :-)
> 
> $ tar ztf php-4.3.10.tar.gz | grep tar | grep pear
> php-4.3.10/pear/packages/HTTP-1.2.2.tar
> php-4.3.10/pear/packages/Net_Socket-1.0.1.tar
> php-4.3.10/pear/packages/Mail-1.1.3.tar
> php-4.3.10/pear/packages/XML_RPC-1.1.0.tar
> php-4.3.10/pear/packages/DB-1.6.2.tar
> php-4.3.10/pear/packages/XML_Parser-1.0.1.tar
> php-4.3.10/pear/packages/Net_SMTP-1.2.6.tar
> 
> $ tar ztf php-4.3.11.tar.gz | grep tar | grep pear
> php-4.3.11/pear/packages/HTML_Template_IT-1.1.tar
> php-4.3.11/pear/packages/Net_UserAgent_Detect-2.0.1.tar
> php-4.3.11/pear/packages/XML_RPC-1.2.2.tar

They are at pear.php.net where they belong.  Only absolutely essential
packages are bundled now.  pear-dev archives have more information on
the (long and drawn-out) decision.

Greg

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-DEV] PHP 5.0.4RC1 and PHP 4.3.11RC1 rolled

2005-03-14 Thread Greg Beaver
Edin Kadribasic wrote:
Windows binaries are now available at:
PHP 5.0.4RC1
http://downloads.php.net/edink/php-5.0.4RC1-Win32.zip
PHP 4.3.11RC1
http://downloads.php.net/edink/php-4.3.11RC1-Win32.zip
Additional downloads for PHP 5.0.4RC1:
http://downloads.php.net/edink/pecl-5.0.4RC1-Win32.zip
http://downloads.php.net/edink/php-debug-pack-5.0.4RC1-Win32.zip
The PEAR bundles are ridiculously out of date for both PHP 5.0.4 and 
4.3.11, where is the windows build pulling these versions from?

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Limit iterations on a foreach loop?

2005-02-11 Thread Greg Beaver
Brian Dunning wrote:
I'm using an RSS feed that has WAY too much content, I only want the 
first 10. I'm outputting the array with a foreach loop: is there a way 
to limit it to only go through the first 10?

Thanks,
- Brian
$i = 1;
foreach ($rsses as $rss) {
if ($i++ >= 10) {
break;
}
}
However, why not use for()?
for($i=0;$i<10;$i++) {
// do stuff
$rss = next($rsses);
}
reset($rsses);
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Global class instances mysteriously set to NULL

2005-01-09 Thread Greg Beaver
James wrote:
I'm struggling to narrow this down, and am chasing my tail to figure 
this out. I apologise for the imprecise nature.

PHP: 4.3.2 (latest RHEL 3 version; php-4.3.2-19.ent.src.rpm)
OS: Linux kernel 2.4.21-15.0.3.EL
Distro: RHEL 3, all updates
I have an app that defines two global class instances, one for the 
database connection, the other for handling user authentication. The 
first is instantiated in uDatabase.php the other in uAuthenticate.php.

In building a page, there are several files that call require_once with 
one or the other file, e.g.

require_once 'uAuthenticate.php';
Which creates an a global instance of a class defined in another file, 
performs some checks, &c.

I'm using require_once with the understanding that once this file has 
been included, that any subsequent require_once call to the same file 
will be ignored.

My problem is that it appreas that in some cases require_once destroys 
the instance, i.e. var_dump($Auth); or var_dump($Database) displays NULL.

I'm currently trying to determine rhyme or reason for the problem, but 
haven't found any pattern. It comes and goes depending on which file 
first calls require_once and the order, but makes no sense.

ANY ideas apreciated. :-)
Since you are using relative includes (require_once 'uAuthenticate.php';)
You must make sure that there is only *1* uAuthenticate.php file being 
included.  To verify that this is the case, try this code at the end of 
the main file:


If you switch the ordering of inclusion and get a different listing, 
there's your answer.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Using the OR operator in an IF statement

2005-01-08 Thread Greg Beaver
Tim Burgan wrote:
Hello,
Can someone please correct me on my efforts below.
If I have a condition where I want to test if a variable is not equal to 
"student", "staff", or "admin".. what's the simplest was to achieve that?

Here's what I tried.. that didn't work:

  if ( ($_POST['usertype'] != "student") || ($_POST['usertype'] != 
"staff") ||  ($_POST['usertype'] != "admin") )
  {
 // ...
  }
?>
use && instead of ||
In english, you'd say "if the usertype is not student and not staff and 
not admin, then we're OK." or "if the usertype is neither student, nor 
staff, nor admin"

neither/nor is implemented using !=/&&
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP5 Namespace ?

2005-01-04 Thread Greg Beaver
Matthew Weier O'Phinney wrote:
* Alawi Albaity <[EMAIL PROTECTED]>:
is really that the support for namespace in php5 is removed ? or there
are replacment for it ?

It's been removed as it's not currently working:
http://php.net/ChangeLog-5.php
My understanding is that it will be at least 5.1 before namespaces are
added -- if then.
It will not be added in PHP 5.x.  6.0 is the next version that will 
consider adding them, unless someone comes up with a brilliant 
implementation that doesn't break everything.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PDFlib-Lite-6.0.1

2005-01-04 Thread Greg Beaver
2wsxdr5 wrote:
I 
am trying to install PDFlib-Lite-6.0.1  on my testing server.  So far no 
luck.  I am starting with php 4.3.3 and apache 2.0 on an SUSE 9.0 
machine.  Apache and php were installed with the OS.  I started by 
getting tiff-3.7.1.tar.gz and jpegsrc.v6b.tar.gz and those both 
installed with out a problem then I got PDFlib-Lite-6.0.1.tar.gz and 
that configured compiled fine then came the problems.  Here is the 
command and out put...

PIII500x2:~ # pear install pdflib
downloading pdflib-2.0.4.tgz ...
...done: 36,082 bytes
7 source files, building
running: phpize
Configuring for:
 PHP Api Version:   20020918
 Zend Module Api No:   20020429
 Zend Extension Api No:   20021010
`phpize' failed
Any ideas?
This is a question for pear-general.
Please specify the output of pear -V, and if you don't see 1.3.4, 
upgrade and try again.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: php5 webhosting

2005-01-03 Thread Greg Beaver
Greg Donald wrote:
Anyone found any good deals with webhosts supporting PHP5 yet?
it's not exactly for newbies, but bluga.net has been doing a fine job 
for me.

Greg
P.S. "ZCE" doesn't exactly imply newbie :) this is for others on the list
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: newbie.. $_GET & $_POST

2005-01-03 Thread Greg Beaver
Pablo D Marotta wrote:
Hi there..
I need to pass variables to a page through an html link.
I do it like this:
Export
where 'buildQuery' is the variable I´m passing.
In the destination page, I capture it with $_GET and that´s it.
I want to know if there is any way of doing it without showing the variables in
the direction bar.
Hi Pablo,
The method you are using to send the query is not a very secure method 
(depending on how you run it.)

Based on the source code shown, I imagine you have something like this 
code in excelListing3.php:

$buildQuery = $_GET['buildQuery'];
somedb_query($buildQuery);
What this means is that someone who knows your database structure can 
type this into their web browser:

http://www.yourhost.com/excelListing3.php?buildQuery=DROP+DATABASE+yourdb
and your program will happily execute it.
Far better is to parameterize your queries and limit the possible input. 
 By this I mean to define a few queries that can be executed, and give 
them numbers

Export

switch ($_GET['queryType']) {
case 'export' :
$query = 'SELECT * FROM yourdb WHERE queryVar1="' . 
mysql_escape_string($_GET['queryVar1']) . '" AND queryVar2="' . 
mysql_escape_string($_GET['queryVar2']) . '"';
}

and so on.  I am assuming here that you are using mysql, but simply 
substitute the appropriate escaping function for another database.

Web security hinges on ensuring that your allowed input is finite and 
verifiable.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] migrating to PHP 5 + Apache 2 from PHP 4.3.8 + Apache 1.3.33.

2005-01-03 Thread Greg Beaver
Symbulos Partners wrote:
There are 4 alternative solutions
0)php 5 + Apache 2
1)php 5 + Apache 2 pre-fork (not totally satisfactory, but better than have
a  system that is unstable)
2)php 5 + Apache 1.3.33 (which is not totally satisfactory, less than 0,1 in
any case, but better than have a system that is unstable)
3)php 4 + Apache 2 (which is not totally satisfactory, less than 0,1,2 in
any case, better than have a system that is unstable)
which one does satisfy your condition of rock solid foundation? Or shall we
stick with php 4 + Apache 1.3.33, which is VERY unsatisfactory because we
cannot use the new object model?
The server is a production server, so we must have rock solid solutions on
it.
php5 + Apache 1.3.33 works just fine, have you tried that?  I would 
DEFINITELY wait until PHP 5.1 to put it into production though, there 
are a number of features being added, as well as the time spent testing 
and developing php 5 will help assure its stability as well.  If you 
have the possibility of setting up a test server on another port to test 
php5 with apache 1.3.33, this will be your safest bet to develop the 
software you will use without compromising the current setup.

You might also experiment with setting up Apache2 on another port, and 
then once you can be sure that your solution works in Apache and in 
Apache2, you have the ability to switch back to Apache in the blink of 
an eye just by modifying which port each process is listening to.  It 
would require maintaining parallel setups for a while, which is a real 
pain, but you would get the cutting-edge features you are looking for 
with a safety fallback, which your clients would be looking for.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: function problem

2005-01-02 Thread Greg Beaver
Hi Viktor,
Viktor Popov wrote:
Hi,
I'm trying to do the following but I don't have any success. Could you help
me here...
I have this code in mu page:

if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
  $$key = $value;
}
This is a huge security hole, far better is to do this:
if (isset ($_POST['submit'])) {
foreach (array('field1', 'field2', 'field3') as $allowedfield) {
if (isset($_POST[$allowedfield])) {
$$allowedfield = $_POST[$allowedfield];
}
}
}
In addition, you really need to use mysql_escape_string() to avoid 
serious potential problems with sql injection attacks.

[NOTE: mysql_db_query() is deprecated, use mysql_query()/mysql_select_db()]
mysql_select_db($DB);
mysql_query('INSERT INTO blahbalhblahblah VALUES("' . 
mysql_escape_string($field1) . '" ');

Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: distributed architecture....

2004-12-30 Thread Greg Beaver
Bruce Douglas wrote:
hi...
i'm contemplating a project where a number of websites would communicate with each other via some network of round robin/distributed servers. Each 'client' website/app would be considered to be a 'node' of the overall network, and be able to upload/download information to the network. The master servers would maintain the information, such that if a request for information came from one of the 'client' sites, the master server would shove the information back to the client for display. 

the overall goal of the project would be a way of allowing a client site to 
'share/exchange' information with other client sites within the network, and to 
allow the content of a given client site to be influenced by the content of 
other sites within the network...
has anybody heard/seen anything like this...??
in searching google/sourceforge/freenet/etc.. i can't find anything that's similar, or that could be used as a starting point for the architecture... the closest i can find is the open source gnutella/limeware p2p app structure...
Do a websearch for XML REST.
Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Data Access Object (DAO) with PHP

2004-12-11 Thread Greg Beaver
Adwin Wijaya wrote:
Hi,
Is there any mature DAO class for PHP (free) ?
http://pear.php.net/DB_DataObject
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multiple Inheritance

2004-12-10 Thread Greg Beaver
Greg Donald wrote:
with it, but I will go grab a PEAR module if it fits my needs. Code
re-use may be the only redeeming quality of OO programming, and
honestly I can re-use your code from a non-OO include file just as
easily.
yep, unless the function names happen to conflict with ones you've 
already written.  Then, you run into the 
oh-crap-I-should-have-planned-to-use-other-code-oh-well-I-guess-I'll-rename-everything-and-waste-hours 
problem.  Class names occasionally conflict, but this tends to be a much 
smaller and simpler search-and-replace.

Until PHP gets namespaces (translation: never), OO is the only way to do 
code re-use.  Of course, most PHP programmers believe it is faster to 
write everything from scratch.

More power to them, I'll use [good] code that already exists over my own 
"brilliant solutions" any day, thank you very much.

I would challenge anyone advocating functions: how many of you have had 
to modify your function-based program to do a similar thing and been 
forced to rewrite?  Even with well-designed functions, you end up with 
this problem - code modification is impossible.  This is why I hardly 
ever use static methods or functions.  Notice - I do use these things, 
but you have to know when it is appropriate to do so.

functions and static methods should be used for code that you can 
guarantee you *don't* want to change - ever (well, at least almost 
never).  Anything that you may need to extend or modify functionality 
must be implemented with something more flexible, or you're going to get 
screwed at some point.  Static methods should be used for any functions 
that are re-distributable so that others can plug them in without risk 
of name conflicts.

If you're writing the code for Yahoo like Rasmus, you're going to write 
the fastest code imaginable, and you will also be working on the C code 
to do things.

If you're writing the code for podunk.com, or even for a mid-level 
traffic site, it is extremely unlikely that you will notice even the 
slightest difference between OO and non-OO code.  The biggest hogs in 
php programming are:

1) unnecessary images and animated crap/unnecessary javascript
2) terrible database usage
3) too much complexity in the design
It doesn't matter whether you are using OO or functions - if your 
application has too many lines of code per task, it won't be fast.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Please save me from insanity - PHP4 / OO

2004-12-05 Thread Greg Beaver
Ben wrote:
class Ob {
var $prop;
}
class Test {
function setMe(&$ob) {
$ob->prop = $this;
}
}
$ob = new Ob();
$test = new Test();
$test->setMe($ob);
if ($ob->prop) error_log("PHP is OK");
You should use "if (is_a($ob->prop, 'test'))"
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Please save me from insanity - PHP4 / OO

2004-12-05 Thread Greg Beaver
Ben wrote:
Thanks a lot for your responses guys. Unfortunately it still isn't 
working for me. I've tried both :

$ob->prop = &$this
and$ob->prop &= $this (just in case)
Neither produce a "PHP is OK".
I'm using version 4.2.2 btw. (If ONLY I was on 5)
Thanks again,
Ben
Greg wrote:
class Test {
function setMe(&$obj)
{
$ob->prop = &$this; // note another &
this line should be $obj->prop = &$this, just a typo
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Please save me from insanity - PHP4 / OO

2004-12-05 Thread Greg Beaver
Ben wrote:
class Ob {
var $prop;
}
class Test {
function setMe(&$ob) {
$ob->prop = $this;
}
}
$ob = new Ob();
$test = new Test();
$test->setMe($ob);
if ($ob->prop) error_log("PHP is OK");
else error_log("PHP is a fucking MARE");
What is my problem here? Please help!
You've run into the "I really need PHP5" problem :)
prop = &$this; // note another &
}
}
$ob = new Ob;
$test = new Test;
$test->setMe($ob);
if ($ob->prop) {
error_log("PHP is more than OK");
} else {
error_log("I forgot the second &");
}
?>
Here's your PHP5 version
prop = $this;
}
}
$ob = new Ob;
$test = new Test;
$test->setMe($ob);
if ($ob->prop) {
error_log("PHP5 is *way* more than OK");
} else {
error_log("This can't happen");
}
?>
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: php 4 to 5

2004-11-28 Thread Greg Beaver
Travis Conway wrote:
I do not know much about the history of php and do not know why there is 
active development on both the 4 and 5 major versions, but is there a 
definite reason for me to migrate from 4 to 5 on my servers?
Depends on what you wish to do with php.
PHP 5 has far better support for xml and soap than php 4.  It has a 
stricter object model and supports native exceptions for error handling. 
  Iterators, reflection, and __call()/__get()/__set() provide 
incredibly flexibility.  It is new, and so not nearly as stable as PHP 
4.  Any solutions would need to be custom-written for PHP 5 at this 
point, although options are beginning to appear.

PHP 4 has a big history and is very stable.  There are shortcomings that 
are addressed in PHP 5, but there is a huge codebase.

So, the question is, do you rely on other people's code, or your own? 
If you rely on other people's code, I would wait a year or two to 
upgrade.  Otherwise, what are you waiting for?

:)
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Overriding static members?

2004-11-28 Thread Greg Beaver
Matthew Weier O'Phinney wrote:
* Francisco M. Marzoa Alonso <[EMAIL PROTECTED]>:
Can I override static members in someway under PHP5? Is the answer is 
negative, Why not?

If they are marked public (or not marked at all as public, private, or
protected, in which case the default is public), then yes, you can
override them.
Override is misleading.  Since they can only be access by 
Classname::$var, unless you use Reflection, code designed to work with 
the parent class can't access the child class's static variables.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Getting static member for a class which name is stored

2004-11-28 Thread Greg Beaver
Jake Press wrote:
Simas Toleikis wrote:
Jake Press wrote:
Hi Francisco,
Your not alone, a number of other users have enountered this bug.

string get_class ( object obj )
Its not a bug...
You are getting class name as a string for output purposes etc..
Doing something like "TestClass"::some_static is ofcourse illegal wih 
strings.

Morning,
Umm, it is an unclear syntax limitation, which is a bug.
... either language or manual.
i understand what you are saying, i beleive i disclaimer'd my own 
examples somewhere down the line in those threads ;)

i beleive there should be a better way to do this without:
- using reflection
- instantiating the class and using a method to retrieve the variable
- eval
Also please notice the existance of the "call_user_func" and what this 
gives us ;)
= this gives us a solution (workaround??) to access static functions 
within a class

Perhaps we need a similar function to provide access to our static 
variables! :)
How about:

echo Myclass::$myvar;
?>
The only problem is if you want to be able to generically access a 
static variable from any class that has it, like $Myclass::$myvar.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Getting static member for a class which name is stored in a variable

2004-11-25 Thread Greg Beaver
Francisco M. Marzoa Alonso wrote:
I've code like follows:

class TestClass {
   public static $Data = 'This is the data';
}
$Obj = new TestClass ();
$ClassName = get_class ($Obj);
echo $ClassName::$Data;
?>
http://www.php.net/manual/en/language.oop5.reflection.php

class TestClass {
   public static $Data = 'This is the data';
}
$obj = new TestClass;
$a = new ReflectionClass('TestClass');
echo $a->getProperty('Data')->getValue($obj);
?>
in PHP 5.1 this should work

class TestClass {
   public static $Data = 'This is the data';
}
$a = new ReflectionClass('TestClass');
echo $a->getProperty('Data')->getValue(null);
?>
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: intalling pear:db

2004-11-25 Thread Greg Beaver
Merlin wrote:
that did not help. The pear manual says that this can be installed via
command line, plus "pear list" tells me that the package is installed.
However if I call phpinfo() there is no mentioning about pear in any 
way?!
Do I have to enable it first anyhow?`
I assume you have very little PHP experience, so I'll try not to skip 
any steps.

Forget pear for now.
in PHP, if you have this file:

then php.exe (on windows) or /usr/bin/php (in unix - path may vary) will 
 read a special configuration variable called "include_path" that looks 
something like this:

.;C:\php4
in windows or
.:/usr/local/lib/php
in unix
PHP will pretend your script is:

and if ./blah.php does not exist, it will try

See?  So, if blah.php is actually located in /usr/lib/php/blah.php, php 
will not find it and cause an error.  So, you have to change the 
include_path


PEAR only installs files, it does not change include_path because this 
is impossible to do automatically.  What you need to do is find the 
location of DB.php, and make sure the absolute path that leads to DB.php 
is in your include_path (/usr/local/lib/php/DB.php, perhaps, or 
C:\php4\pear\DB.php)

Having said this, the error you are experiencing sounds like a bug in 
the code.  There are two possibilities

1) there is a file named "DB.php" located in the "." directory, that is 
being included *before* pear's db would be included
2) there is an ancient version of DB.php that is being included before 
pear's DB.php

the get_included_files() function can help you lots on this one
http://us2.php.net/manual/en/function.get-included-files.php
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: intalling pear:db

2004-11-24 Thread Greg Beaver
Merlin wrote:
Hi there,
I am trying to get a class running which requires pear:DB.
I downloaded the package and executed:
# pear install DB-1.6.8.tgz
DB already installed
pear upgrade DB-1.6.8.tgz
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: What should I name my base class?

2004-11-17 Thread Greg Beaver
Brent Clements wrote:
I know this probably doesn't matter, but what is the pretty standard naming
convention for base class names?
Should I name it "base.class", "main.class", or the name of my application,
"application.class"?
What does everyone else use?
Avoid base classes like the plague.  They only limit future flexibility. 
  Use inheritance like salt - as an enhancement for flavoring, 
otherwise you might develop high blood pressure ;).  Better is to use 
delegation, factory or singleton as a way to access needed features, 
because then you can easily plug in new base functionality.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] debug_backtrace bug?

2004-11-17 Thread Greg Beaver
Marek Kilimajer wrote:
The 'class' index reflects what __CLASS__ constant would show. Bug report:
http://bugs.php.net/22960
Status: It works as expected and intended.
right, but this states that __CLASS__ is bar inside bar::b() and is foo 
inside foo::b().  In this case, debug_backtrace() is reporting that 
__CLASS__ is foo inside bar::b().

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP 4 to 5 class issues involving static methods and $this

2004-11-17 Thread Greg Beaver
Chris wrote:
I have a class where I need to be able to use the methods as static  
methods as well as using them inside an initialized class.  Here's an  
example of what I need to do:

class my_class {
var $elements = array(); // holds all of my elements
function format_string($string) {
// format the string...
return $this->elements[] = $string;
}
function show_all() {
return implode("\n", $this->elements);
}
}
This worked fine in PHP 4.  It silently ignored the $this->elements[]  
assignment in statically called methods and just returned my formatted  
string without any fuss.  However, in PHP 5, I understand that I'm now  
required to declare the method format_string as public static if I want 
to  just call my_class::format_string(), and if I want to use $elements 
inside  a static method, it also requires being declared as static.  I 
also  understand that I can't use $this inside a statically called 
method.  I've  tried these things, but they don't seem to help.

How can I rewrite my class for PHP 5 to emulate the functionality I had 
in  PHP 4 in an error free way?
elements[] = $rm->invoke(null, $args);
} catch (ReflectionException $e) {}
}
}
static_my_class::format_string('a');
$a = new my_class;
$a->format_string('a');
?>
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: debug_backtrace bug?

2004-11-17 Thread Greg Beaver
Thomas Peri wrote:
I wanted to run this past the list before submitting a bug report.  
(I've searched the bugs and haven't found anything relevant to my problem.)

The problem is that when s method of one class is overridden in a 
subclass, debug_backtrace() doesn't distinguish between the two 
methods.  For example, this code:

class A {
function __construct() {
$bt = debug_backtrace();
foreach ($bt as $t)
print $t['class']."::".$t['function']."";
}
}

class B extends A {
function __construct() {
parent::__construct();
}
}

$b = new B();

...produces this output:
B::__construct
B::__construct
...instead of the output I'd expect:
A::__construct
B::__construct
It happens for regular methods also, not just constructors.  Is this a 
bug, or is this behavior correct for some reason?  (Tested in php 5.0.0, 
5.0.1, and 5.0.2)
This looks like a bug to me, open a report.
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Array unset

2004-11-17 Thread Greg Beaver
Bruno b b magalhães wrote:
So, the question, how resort the numeric values to 1,2,3,4?
http://www.php.net/array_values
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Globally accessible objects without using 'global $obj;'

2004-11-12 Thread Greg Beaver
Chris W. Parker wrote:
What I'd ultimately like to do is be able to return more than just a
true/false from a function regarding it's end state. For example, a
function could fail for multiple reasons and just returning a plain
false for all situations does not suffice.
You could either return an object like PEAR_Error 
(http://pear.php.net/manual/en/core.pear.pear-error.php) or use a more 
customizable solution like PEAR_ErrorStack 
(http://pear.php.net/manual/en/core.pear.pear-errorstack.php).  Also, 
don't forget about built-in options like trigger_error and Exceptions in 
php5.

More important than what you use is planning for future growth.  Your 
applications will get larger.  It may seem like a time-saver to do a 
quickie fix that requires less initial typing, but I guarantee you will 
run into a brick wall when you do have to change things and be forced to 
rewrite everything - not exactly a timesaver, unless you simply give up 
on making your code better :)

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: adding a space every 4 chars

2004-11-11 Thread Greg Beaver
Justin French wrote:
Hi,
What's the quickest way to add a space every four characters?
Eg 123456789 becomes 1234 5678 9

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: name of the function

2004-11-03 Thread Greg Beaver
Gustavo A. Baratto wrote:
hello there,
is there anyway to know the name of the function that is being executed?
In the docs (http://www.php.net/manual/en/ref.funchand.php),  we can 
find out the arguments of the function, but not the name of the function 
itself.
echo __FUNCTION__;
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PEAR Calendar

2004-11-03 Thread Greg Beaver
Greg Donald wrote:
On Wed, 03 Nov 2004 16:28:13 -0500, Greg Beaver <[EMAIL PROTECTED]> wrote:
Install it manually.
http://pear.php.net/manual/en/installation.manually.php
This is terrible advice.
$ pear install --force Calendar.

And you think --force is better?  Pffft.
When the PEAR developers make an entire webpage with specific
instructions for installing a PEAR module manually, I gotta think it
isn't 'terrible advice' to post the URL to it.
In this particular case, he already has a fully working PEAR install. 
The solution you gave was to the wrong problem.  manual install is only 
for those who can't use the command-line or web installer.

However, the error message given by the pear installer is incredibly 
unhelpful as it doesn't say that there is a non-stable version 
available, and doesn't tell you how to install it.  This has been fixed 
in the latest PEAR in CVS along with lots of other goodies.

His problem is that Calendar does not have a stable release, and there 
was no obvious way to install it.  Doing a manual installation is risky 
for several reasons

1) any replacements in the package will not be executed (advanced packages)
2) dependencies are not checked before installation, leading to all 
kinds of potential problems.

Incidentally, I just committed code on Sunday that will make the manual 
installation instructions obsolete.  Now, you'll be able to 
automatically use the PEAR installer to synchronize a remote 
installation with a local one through ftp, eliminating both of the 
problems listed above.  This will be in PEAR 1.4.0+

I am sorry I jumped on you Greg, you have given great advice very often 
on this list.  My country is going to Hell, and I took a bit of 
frustration out on you :)

Greg
P.S. my Dad's name is Donald :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PEAR Calendar

2004-11-03 Thread Greg Beaver
Greg Donald wrote:
On Wed,  3 Nov 2004 15:41:54 +0800, Roger Thomas <[EMAIL PROTECTED]> wrote:
I would like to install PEAR Calendar  module and did a
[EMAIL PROTECTED] apps]# pear install Calendar
but got these:
No release with state equal to: 'stable' found for 'Calendar'
Please advise.

Install it manually.
http://pear.php.net/manual/en/installation.manually.php
What?!?!
This is terrible advice.
try:
$ pear install Calendar-beta
or
$ pear install --force Calendar.
Greg
P.S. you should post to php.pear.general or write to 
[EMAIL PROTECTED] for PEAR-related questions.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: An easier way? $_POST[] => $_SESSION[]

2004-11-01 Thread Greg Beaver
Erich Kolb wrote:
Is there an easier way to assign all post data from a form to session data?
Eg.,
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['email'] = $_POST['email'];
Never pass in data from any external source without explicitly 
validating it.  You could run into some serious crap if malicious users 
attempt to pass in very large chunks of BS into random $_POST variables, 
and you simply save it in $_SESSION.  For instance, if you have any 
quota, you might exceed it in a single bound, and your whole site would 
stop working.

so, the way you're doing it is a lot better than any other options, but 
I would add in checks to the values before you save them in $_SESSION.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP_EOL on Darwin?

2004-10-31 Thread Greg Beaver
Hi all,
What's the standard line ending for Darwin?  is it still the same as old 
Mac, which I think was just \r?  Or does it use \n like unix?

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Require_once(_)...when does it reset?

2004-10-28 Thread Greg Beaver
Mike wrote:
I am playing with PEAR_Info on my server. It was working fine, then I
upgraded some classes, now it is not.
I think it is because PHP is holding on to the old code from some
require_once functions.
I may be totally wrong but that is all I can think of what would cause this.
Other classes (that I did not execute before updating) work fine.
Is there a way to reset PHP if this is the case?
What did you upgrade?
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Add methods to object dinamically

2004-10-26 Thread Greg Beaver
Francisco M. Marzoa Alonso wrote:
I've seen that's possible to add members to objects dinamically, in 
example:

class MyClass {
   private $a;
}
$MyObject = new MyClass ();
$MyObject->b = 1;
Now $MyObject has a public member called 'b' that has a value of '1'.
The question is, is it possible to add methods in the same way?
I meant something such as:
function sum ( $this ) {
   return $this->a+$this->b;
}
$MyObject->sum = sum;
Note that code will not work, but it illustrates what I'm asking for.
Sort of :)
In PHP5, this will work.
_methods[$method])) {
$call = $this->_methods[$method];
return $call($this);
}
}
public function __set($var, $value)
{
if (is_string($value) && is_callable($value)) {
$this->_methods[$var] = $value;
} else {
$this->$var = $value;
}
}
}
function test($o)
{
return $o->val;
}
$o = new DoesStuff;
$o->val = 4;
$o->test = 'test';
echo $o->test();
?>
However, you won't have access to private or protected data members.  It 
is always better to rigidly define your methods, and extend the class as 
someone else suggested.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Good Class/API Design ?

2004-10-25 Thread Greg Beaver
Adam Reiswig wrote:
Hey all, I just got my hands on the excellent books PHP Anthology 1 & 2 
and am wanting to start playing around with classes.  My question to the 
list is, what, in your opinion, constitutes good class/api design?  Is 
it better to design several smaller classes that each focus on one task 
and do that task well, or to build more general classes that handle a 
number of related tasks?

Also, when you are beginning a new project, what methods do you find 
helpful to follow in taking your project from concept to finished?
Do as much of the design away from the keyboard as you can.  Use prose, 
questions like "what do the users of this program need?" are a good 
starting point, or "what is the problem that needs solving?"  Draw 
pictures and flowcharts for complex things you want to do (you don't 
have to use UML, but its methodology is helpful).  There are several 
excellent and free UML modelling programs out there.

The books also mention ways to use phpDocumentor to document your code 
and SimpleTest to test your code as it is written.  These along with 
some XP techniques I read about seem like good practices to follow. Does 
anyone have any other ideas/practices that it would be good for a new 
oop developer like myself to make a habit it of?
The main advice I can offer as one of the primary authors of 
phpDocumentor, the next incarnation of the PEAR installer (not out yet), 
and a few other small packages is to start small, and use code that 
others have written wherever possible.

When code I've written gets old, the first thing I notice is that the 
best code has been split up so that methods are no longer than a page, 
and classes don't try to group more than one thing.  A great rule of 
thumb for all functions is to ask yourself

"What is the one thing I want this to do?"
If your function starts doing more than one thing, split it up.  It will 
also get to be much longer than a page, so that's a good warning sign.

I've also gone the other route, which is to say I tried to over-OO 
things with my defunct first attempt at the PEAR package Games_Chess. 
Initially, each piece was an object, and so was each square on the 
chessboard.

Calculation is virtually impossible in this situation.  Then, I realized 
that pieces don't need to do any actions, and only possess two 
properties, their color and their name.  Changing the design to use 
properties of a chess object to represent the board as an array and each 
piece as an index in this array suddenly made it possible to do very 
fast calculations using the array functions built into PHP, and suddenly 
it took only a week to come up with a working first draft.

The other thing I've learned the hard way is for God's sake, don't write 
code like this:

class Common
{
function utilitythingo()
{
}
}
and extend every other class from Common.  This instantly cuts down on 
future expandability options.  It means when you realize that you've 
designed the application to solve the X problem, and the more important 
problem was Y, modifications will take you forever.  Or, when you find 
code that someone else has written, you won't be able to easily 
integrate it into your own code.

The single most important design decision is not just how you split up 
the tasks, but how you design the communication between them.  You can 
have methods instantiate objects directly, pass in objects, use a 
proxy/router object to communicate between classes using messages or 
simply call methods directly - the choices are endless.

For instance, logging is a common idea for most web applications.  If 
you design all classes that do logging so that they simply accept an 
instantiated logging object, this will allow you to plug and play ANY 
object that has the same API as your preferred logging object.  The same 
is true of database access, or other critical design choices.  Patterns 
can often be useful in deciding how to do things, such as the faddish 
MVC (model-view-controller) or singleton, factory, observer patterns. 
Go to http://www.phppatterns.com to see Harry Fuecks's excellent site 
devoted to these subjects.

However, most important is to simply try it out, make mistakes and have 
fun trying to fix them (or get an ulcer, but that's how we look at 
things, isn't it :)

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Pure PHP menu tree

2004-10-25 Thread Greg Beaver
Ryan A wrote:
Hi,
I have been searching on the net for the past 2 hours without success, so
need a recommendation now :-)
Basically i am looking for a PHP "menu tree", looking on google I have found
many but most of them use Javascript with php, or are pure JS or DHTML, I
want one that is pure php so it will work accross all browsers.
http://pear.php.net/package/HTML_Menu
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP 5 abstract method and class type hints of extending classes

2004-10-25 Thread Greg Beaver
Jeremy Weir wrote:
The quesion is: how would one make an abstract method that can be compatible 
with all extending classes that define the method using different class type 
hints?

The php block below is how I thought it should work, but will give this 
error at parse time:
Fatal error: Declaration of DisplayObjectOne::display() must be 
compatible with that of DisplayBase::display()
because the hint in the concrete method is different from that in the 
abstract method.


// display ObjectOne
class DisplayObjectOne extends DisplayBase {
public function display(ObjectOne $object){
print_r($object);
}
}
// display ObjectTwo
class DisplayObjectTwo extends DisplayBase {
public function display(ObjectTwo $object){
var_export($object);
}
}
If you use type-hinting, this is a more strict contract.  You're telling 
PHP that "this method must receive an object that is of this class or 
any subclass"

in DisplayObjectTwo, you're saying "this method CANNOT accept a 
DisplayBase or any child object unless it extends ObjectTwo"

In other words, imagine if what you want to do was allowed.  Someone 
comes along who writes a method that uses an instanceof test like:

$b = new ObjectOne;
$a = new DisplayObjectTwo;
if ($a instanceof DisplayBase) {
$a->display($b);
}
to display another object, you get a serious problem, because the code 
will fail with all DisplayObject* that aren't DisplayObjectOne, but the 
instanceof test will succeed!

In other words, your display() function is in fact not a generic 
function, but is specific to each class, so the use of a DisplayBase 
class makes absolutely no sense at all.  Better is to implement a method 
inside ObjectBase called getDefaultDisplayObject() which will 
instantiate the display object that is needed.  Custom classes can then 
override this method to return the custom display object.

Even though it is better, this still isn't great design.  What you 
probably want is this:

abstract class DisplayBase
{
public static function factory(ObjectBase $o)
{
$class = 'Display' . get_class($o);
if (!class_exists($class)) {
throw new Exception('No display object for "' . 
get_class($o) . '"');
}
$disp = new $class($o);

}
abstract public function __construct($o);
abstract public function display($options); // might want this
}
class DisplayObjectOne extends DisplayBase
{
private $object;
public function __construct($o)
{
if (!$o instanceof ObjectOne) {
throw new Exception('parameter must be an ObjectOne');
}
$this->object = $o;
}
public function display($options)
{
print_r($this->object);
}
}
class DisplayObjectTwo extends DisplayBase
{
private $object;
public function __construct($o)
{
if (!$o instanceof ObjectTwo) {
throw new Exception('parameter must be an ObjectTwo');
}
$this->object = $o;
}
public function display($options)
{
print_r($this->object);
}
}
Now, your hypothetical user can do
try {
if ($d instanceof DisplayBase) {
$d->display($options);
}
} catch (Exception $e) {
// handle problems
}
and rest assured that the code will work under all circumstances.  Hope 
this helps :)

Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: clearstatcache, how to use?

2004-10-25 Thread Greg Beaver
Louie Miranda wrote:
I have this code that checks for a file if it exists and do something
if it doesnt exist. Problem exist when im updating my data on the
directory, even if i did upload it. it still shows the non-existent
data.
I have read that i should add the clearstatcache();, how am i going to
use it? after the file_exists? or before?
here's my code
##
$itemCode_SHOW = $row[2];
$filename =("/www/images/stockprod/$itemCode_SHOW.jpg");
if (file_exists($filename)) {
$itemCode_SHOW = $row[2];
} else {
$itemCode_SHOW = "noimage";
}
clearstatcache();
##
clearstatcache() is very descriptive for php, actually :).  Most 
filesystem functions make use of statistics about a file.  Gathering 
this information is expensive, so it is cached.  If something changes, 
you have to clear the cache to see the change, so:

clearstatcache();
if (file_exists($filename)) {
is what you need
if (file_exists($filename)) {
...
}
clearstatcache();
will have no impact on the problem, because you are clearing the cache 
*after* the function that relies on the cache has been called.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] special request for windows 98 users to help develop PEAR's pear.bat

2004-10-23 Thread Greg Beaver
Hi,
In the effort to improve pear.bat for windows users, I would like to ask 
any windows 98 users that are still left to try this simple test:

open a MS-DOS prompt and type:
C:\> mkdir C:\test
C:\> mkdir C:\test\me
C:\> echo "echo %~d0%~p0" > C:\test\me\test.bat
C:\> \test\me\test.bat
C:\> cd \test\me
C:\test\me> test.bat
If you don't see as output:
C:\> echo C:\test\me\test.bat
C:\test\me\
for the first and
C:\test\me> echo C:\test\me\test.bat
C:\test\me\
that's a problem.  Please mail me OFFLIST any results, positive or 
negative.  (On windows XP, %~d# where # is a number will spit out the 
drive, and %~p# will spit out the full path, I would like to see if this 
works in windows 98 as well)

Many Thanks,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: parsing a string

2004-10-20 Thread Greg Beaver
Dan McCullough wrote:
Hey everyone
 
Having a bit of trouble with something.
 
I have a string which has known patterns.
 
$string"CampusBob (Williams)~\toms more crap)~\blah blah blah)~\";
 
What I am looking for is 
 
Location which is Campus
  Location Name which is Bob (Williams)
$x = explode('~', $string);
list($location, $name) = explode('', $x[0]);
Make sure that for each \ in the string, you use \\ (that's why there 
are 10 in my example.  If you have 5 \ you need 5 \\)

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PEAR status on PHP5?

2004-10-12 Thread Greg Beaver
Adrian Madrid wrote:
Is PEAR stable on PHP5? I'm trying a new project on PHP5 and keep 
getting different kinds of errors (deprecated, etc.) on DB.php, 
PEAR.php, etc. Looks like so far there has been no show stoppers but it 
would be nice if it wouldn't give errors. What's the status on this? Has 
anybody used PEAR and PHP5 on a production environment succesfully yet?
You need to set error_reporting to E_ALL, instead of E_ALL | E_STRICT. 
All errors will disappear.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Naming conventions

2004-10-01 Thread Greg Beaver
Jason Davidson wrote:
Oh please dont start a thread on which is better .. 
but i beleive it was decided that camel case is the standard now.
Jason

"Jensen, Kimberlee" <[EMAIL PROTECTED]> wrote: 

What do you use for your naming conventions for
variables
functions
classes
I'm trying to tell my students what the standard is currently. Are people using
camel case or underscores or both?
The standard in built-in PHP functions is underscores for procedural 
code (simplexml_load_string) and studlyCaps/CamelCaps for 
object-oriented code.  classes are named using CamelCaps 
(SimpleXMLElement) and methods are named using studlyCaps 
(SimpleXMLElement->attributes(), simpleXMLElement->asXML()).  It would 
be best to adhere to this standard, regardless of personal convictions, 
as any class that extends a built-in class will otherwise end up with a 
medley of method-naming conventions.

Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Version Controlling

2004-09-26 Thread Greg Beaver
Stephen Craton wrote:
This is slightly off topic, but I feel it's a little something that's worthy
of discussion here. I've been interested in running CVS for a while now, but
being on a Windows machine is holding me back somewhat, and I'm not entirely
sure CVS is even something I need.
Basically, I have some computers, mostly my laptop and desktop, and I want
to be able to sync them based on version controlling, much like CVS, but I'm
not sure if it's too advanced or not.
My basic question is: What do you do, if anything, for syncing/version
control between your computers for your web development projects?
There are many solutions, but better than using a constant version 
control system like CVS or subversion is to use cvs/subversion for 
development only.  When things seem to be working, make a release tag, 
and bundle up that code as a package.  You can either zip it up and 
unzip on the production server, or use the pear installer's built-in 
capabilities to customize things.

This strategy is much better, because if it turns out a slight 
difference between your computers breaks the code, you can quickly and 
easily revert to an earlier release (especially if you use the pear 
installer).  If you use the PEAR installer, you can also use the 
dependencies feature to split your code up into smaller chunks, making 
maintenance of large projects even simpler.

use TortoiseCVS, you will never have doubts about how easy it is to use 
cvs on windows again.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Good xml to array class?

2004-09-22 Thread Greg Beaver
Yann LarrivÃe wrote:
Go with SimleXML it's a PHP extention.
Yann
simplexml is PHP 5, and relies on libxml.  If you don't have DOM, you 
don't have simplexml.  Also, simplexml cannot be serialized in any form 
other than an xml string.  If you wish to work with actual arrays (for 
instance, if you're returning values through xml-rpc or soap), you will 
be better off with XML_Serializer.

Otherwise, simplexml is truly magnificent.
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Good xml to array class?

2004-09-22 Thread Greg Beaver
Brent Clements wrote:
I've done searching on google for "xml parsers" and xml to array using php and 
honestly there are S many. Most of the classes I've taken a look at either aren't finished, 
or require dom to work.
Either I write my own or I get help from you guys.
So me being the lazy person that I am will ask you guys.
Anyone know of a very good xml to array class that is available as open source?
I need it to not rely on DOM since the php which I am dealing with, only has expat compiled in. 

Thanks for any pointers to good classes!
This one's easy.  There's only 1 reasonable choice:
http://pear.php.net/XML_Serializer
Not only is the package good, it's maintained by one of the best XML 
coders in PHP-land.

Regards,
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Strange errors when PHP script called from CRON

2004-09-22 Thread Greg Beaver
Pablo Gosse wrote:
The script which is called by my crontab to start this process executes
every minute, so I find it very strange that I'm getting these sporadic
error messages.
Can any one shed any light on this for me?
Does your crontab script use file locking to make sure that it isn't 
accessing a script at the same time as the webserver or another process?

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: readdir behavior I cannot understand

2004-09-19 Thread Greg Beaver
Jason Fb wrote:

$root_dir = "/Users/jason/Sites/";
$folder_on_server "test";
This should be:
$folder_on_server = "test";
T_CONSTANT_ENCAPSED_STRING is a long way of saying a string that doesn't 
have any fanciness in it like "test" or 'hello', but not "this $way" 
because $way is a variable that will be interpreted.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] List Etiquette

2004-09-18 Thread Greg Beaver
PHP Warning: Missing forest, too many trees.
Lots of you are good coders, I've seen you devote immense time and
enegry to crafting informative and helpful posts for years, let's just
move on and read messages using incredibly normal skills like short-term
memory and index finger dexterity for your mouse scroll button.
to Andre: it doesn't matter whether you bottom OR top post, the only
universally important etiquette is to trim all previous replies that you
are not *directly* responding to (establishing context), and then it
won't matter which side of the post you put your reply.  The main point
is don't make people read stuff that is irrelevant, they don't like that.
Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Splitting 12345 -> 1,2,3,4,5

2004-09-16 Thread Greg Beaver
Martin Holm wrote:
Michael Mao wrote:
Thanks John.
Found what I'm looking for:
Function str_split()
to make it php4 compatible you can use this function:
|
if (!function_exists('str_split')) {
  function str_split ($str, $size = 1) {
 $arr = array();
 for ($i = 0 ; $i < strlen($str) ; $i += $size) {
$arr[] = substr($str,$i,$size);
here, you can also use:
$arr[] = $str{$i};
and use $i++ instead of $i += $size
if you don't need strings larger than 1 character.
 }
 return $arr;
  }
}
?>
works in about the same way as the function in php5.
|
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Splitting 12345 -> 1,2,3,4,5

2004-09-15 Thread Greg Beaver
Michael Mao wrote:
Anyone know how I can split a number into individual digits?
If you want to be funky, you can try

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: XML parser for PHP5

2004-09-15 Thread Greg Beaver
Matthew Sims wrote:
My fault, I should have been more specific. An RSS reader. :) I was using
xmlParser-0.3 and feedParser-0.5 to display news sites. Since I've
converted to PHP5, they no longer work for me.
definitely a combination of simplexml and DOM would work.  You need DOM 
in order to determine what the name of the root node's namespace is to 
find RSS 1.0.

http://php.net/simplexml
http://php.net/DOM
for example:
http://www.example.com/blah.rss');
$dom = new domdocument("1.0");
$dom_rss = $dom->importnode($rss, true);
$dom_rss = $dom->appendchild($rss);
if ($dom_rss->namespaceURI == '') {
$rssversion = '1.0';
} else {
$rssversion = $rss['version'];
}
switch ($rssversion) {
case '1.0' :
case '2.0' :
if (isset($rss->channel->pubDate)) {
echo "Publication Date: " . $rss->channel->pubDate . "";
}
case '0.91' :
case '0.92' :
case '0.93' :
case '0.94' :
echo '' . $rss->channel->title . '';
foreach ($rss->channel->item as $item) {
echo $item->title . '';
echo '' . $item->description . '';
}
break;
}
?>
Of course, the full range RSS tags are available to you as object 
properties, and attributes as array access (like $rss['version'])

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: XML parser for PHP5

2004-09-15 Thread Greg Beaver
Matthew Sims wrote:
Anyone know any good XML parsers that work with PHP5? Most of what I can
find on freshmeat are still using PHP4 classes and Google isn't turning up
much either.
What do you want to do?  This parses xml pretty well:

as does this
load('filename.xml');
?>
The first one is brilliant for reading xml whose structure you know, the 
second is better for xml whose structure you wish to manipulate or 
transform.

best, it's built into PHP.  If you want a system that can be easily 
serialized and unserialized as an object (as in sessions), you're 
probably best off using XML_Serializer from PEAR, as neither simplexml 
nor DOM retains any useful information when serialized and unserialized.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: extended class question

2004-09-13 Thread Greg Beaver
Hello again Ed,
This is a tricky thing.  When you define a variable as being private, it 
literally becomes unavailable to child classes, and exists only as the 
var1 variable in objects of class test.  To prove this, try:

a;
}
function seta($a)
{
$this->a = $a;
}
}
class b extends a {
private $a;
function echoa()
{
echo 'this ' . $this->geta() . "\n";
echo 'parent ' . parent::geta() . "\n";
}
function seta($a)
{
$this->a = $a;
parent::seta($a - 1);
}
function geta()
{
return $this->a;
}
}
$b = new b;
$b->seta(2);
$b->echoa();
?>
you can replace the "private $a" in class b with "protected $a" or 
"public $a" with no errors whatsoever, in essence the private variable 
$a has no name outside of the a class - that's what makes it private.

It's a nice feature.  Now we no longer need to document private 
variables.  Users of our classes can simply ignore them and even name 
their own variables exactly the same way with impunity.

Greg
Ed Lazor wrote:
How come the output to this script is "World Trade Center" instead of "Pizza
Delivery"?
Thanks,
Ed


class test {
private $var1;

function __construct() {
$this->var1 = "World Trade Center";
}

function get_var1() {
return $this->var1;
}

function set_var1($data) {
$this->var1 = $data;
}
}
class testing extends test {
function __construct() {
parent::__construct();
$this->var1 = "Pizza Delivery";
}
}
$test2 = new testing();
print "var1 = " . $test2->get_var1() . "";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Class dependencies

2004-09-11 Thread Greg Beaver
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PHP5 OOP

2004-09-10 Thread Greg Beaver
Greg Donald wrote:
On Fri, 10 Sep 2004 15:09:57 -0700, Ed Lazor <[EMAIL PROTECTED]> wrote:
Any recommendations on the best PHP5 OOP book to get?  I have Advanced PHP
Programming by George Schlossnagle.  It's turning out to be a great book,
but I'd like to read more on PHP5 OOP.  The first chapter recommends two
books, but both deal with OOP from the perspective of C++, C#, and Perl.

Do not bother to get "PHP5 and MySQL Bible" unless you're a complete
PHP beginner.  The one OO chapter is not much more than is in the PHP
manual.  I got it and wish I hadn't.  Overall it's long-winded and the
humor is dry.  Tons of useless chatter in between the information you
really want.
Honestly, if you want to learn OOP in php5, the best way to do it is to 
get an IDE that contains a PHP 5 step-through debugger such as Zend IDE 
and try out the stuff you see in the link from the php.net home page 
regarding Zend Engine 2.  It is very similar to java/c# and perl in 
terms of the similarity to those features (exceptions, try/catch, PPP 
are all from those languages).  The big changes are the new xml 
extensions and their derivatives like simplexml, dom, soap.  Learning 
the DOM extension and simplexml is very difficult to do without some 
kind of prior knowledge of DOM, but you'll learn more from sites like 
w3cschools.com than you will from a book.  In addition, ReflectionClass 
is your friend, as in:

getMethods());
// or even
$a = new ReflectionClass('ReflectionClass');
var_dump($a->getMethods());
?>
I would recommend starting with the big red "Beginning PHP4" and then 
simply using trial and error to learn the differences with PHP5, it's 
not all that different from php4 in the basics, it is a question of how 
you use it.

Greg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Can I name a session variable using another variable?

2004-09-10 Thread Greg Beaver
Hi John,
I would recommend making $_SESSION['prevtime'] an array
$roomname = 'sampleroom';
if (!isset($_SESSION['prevtime'])) {
$_SESSION['prevtime'] = array();
}
$_SESSION['prevtime'][$roomname] = time();
Then, you can
if (isset($_SESSION['prevtime'][$roomname])) {
// update the session subvariable, or use it
} else {
// create the session subvariable
}
Regards,
Greg
John Gostick wrote:
Hi,
I've encountered a problem I can't seem to find much reference to on the web, so I 
was wondering if anyone here could help me...
Fisrt a brief background:
I am building a fairly simple PHP/MySQL chat system with multiple rooms. Each room is loaded from the main chat page by clicking on a link that uses JavaScript to open and size a new window, and also passes the roomname as a variable to the new chat window. Messages sent from a room are tagged with the roomname, and the window refreshes periodically to look for new messages(rows) in the database that have that rooms name. In this way a room only recieves messages meant for it. So far so good. However, to determine what messages are new, a SESSION variable $prevtime is set each time the script checks for new messages, so that next time it checks, it will only download messages posted SINCE the time given in $prevtime. This was not a problem with a single room, but when multiple rooms are open they are sharing the same session variable $prevtime because they are all using the same session as they were all opened from the same window. This leads to 'skipping' of messages and 
not all messages being picked up by each room.
I've stratched my head over this, and decided to try and generate a unique SESSION 
variable for each room, named using the string 'prevtime' prefixed with the value of 
the variable $roomname (the name of the current room). However I can't seem to get 
this to work.
To summarise my problem: Can I name/create a session variable like this?:
$roomname="sampleroom";
$_SESSION["$roomname" . "prevtime"]=time();
With the aim of making a session variable named 'sampleroomprevtime'. It is possible 
to use a variable in naming a session this way? I would really appreciate any help 
anyone could give me in making this work, or any suggestions of a better way from 
people with a much better knowledge of sessions than myself!
Thanks in advance,
John
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


  1   2   3   >