Re: [PHP] Replacing special characters with their HTML equivalents

2008-12-21 Thread Larry Garfield
On Sunday 21 December 2008 5:30:25 pm James Colannino wrote:
> Hey everyone.  I have a question.  I have a web scraper that grabs
> information from web pages that often contain characters such as vowels
> with umlots (I know I spelled that wrong.)
>
> The data is editable, so the characters show up unmodified in an
> editable text box.  However, when I try to import the data into a MySQL
> database, the first occurrence of such a character, along with the rest
> of the string, is truncated from the result.  Not all special characters
> cause the problem; vowels with macrons work, for example.
>
> I don't know if it's failing during the actual query or if the character
> is being filtered out at some earlier stage, but whatever the cause,
> it's not working.
>
> My question is, is there a way to replace these characters with their
> HTML equivalents?  For example, the a with an umlot over the top is
> ä in HTML, so before the query is made, and before the filtering on
> the string is done, I'd like to replace that special character with its
> HTML representation.  This allows the user to see the character while
> it's in its text box, yet at the same time allow it to be successfully
> imported into the database.
>
> I know about str_replace, but assuming it's the right function for the
> job, how would I go about representing these special characters in PHP
> so that it will understand what I'm trying to do?
>
> Thanks!
>
> James

You may find this useful:

http://www.garfieldtech.com/blog/unicode-8-vs-16

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] MERRY XMAS

2008-12-24 Thread Larry Garfield
On Tuesday 23 December 2008 9:59:40 pm German Geek wrote:
> Merry xmas to everyone! Thanks for the support and fun discussions.
>
> Regards,
> Tim

foreach ($php_general->subscribers() as $subscriber) {
  foreach ($subscriber->holidaysCelebrated() as $holiday) {
print 'Happy '. $holiday->name() .', '. $subscriber->name() .'!'. PHP_EOL;
  }
}

-- 
Larry Garfield
la...@garfieldtech.com

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



[PHP] Decorator with public methods

2008-12-26 Thread Larry Garfield
Excuse me a moment while I delve into complex OO. :-)

I have an object to which I want to add behavior (methods).  I cannot use 
inheritance here because the object is already of a type or subtype (vis, I am 
already using inheritance for something else), and because I want to be able 
to add multiple types of behavior at runtime.  The normal OO response to this 
situation is the Decorator pattern.



interface F {
  function doStuff();
}

class Foo {
  function doStuff() { ... }
}

class Decorator implements F {
  protected $foo;

  function __construct(Foo $foo) {
$this->foo = $foo;
  }

  function doStuff() {
$this->foo->doStuff();
  }
}

class Bar extends Decorator {
  function doThings() { ... }
}

$f = new Foo();

$b = new Bar($f);
$b->doStuff();
$b->doThings();



OK, great, that's wonderful.  You can also nest such decorators indefinitely, 
provided that they only override methods from Foo and change its behavior, 
then pass on up the chain.  Neat.  What you cannot do, however, is nest 
decorators that have public methods.  That is:



class Baz extends Decorator {
  function doOtherThings();
}

$f = new Baz(new Bar(new Foo));
$f->doOtherThings(); // Works.
$f->doStuff(); // Works.
$f->doThings(); // Fail.



Now, PHP does have a loophole around this problem in the form of __call().  
Specifically, instead of Decorator wrapping each method of F/Foo directly it 
implements __call():


class Decorator {
  protected $foo;

  function __construct(Foo $foo) {
$this->foo = $foo;
  }

  function __call($method, $args) {
return call_user_func_array(array($this->foo, $method), $args);
  }
}


That should work and allow the code snippet above to run, but it has two 
significant problems:

1) Because Decorator does not directly implement F, you cannot use type 
hinting.

2) __call() and call_user_func_array() are both fairly slow operations, and 
stacking them then becomes a nightmare for performance.

#1 can largely be solved by both directly implementing F *and* implementing 
__call(), but we're still left with the performance problems of #2.  While for 
some uses cases that is OK, it can add up to unpleasant microseconds lost.

Can anyone suggest an alternate solution that has less of a performance hit?

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Do defined variables exist at application scope, or session scope?

2008-12-26 Thread Larry Garfield
On Friday 26 December 2008 11:54:30 pm Murray wrote:
> Hi All,
>
> In the index.php file of my application I define several variables,
> including such things as the base path of the app, and the theme path etc.
>
> Since I use 'define()' to do this, are these variables available to my app
> regardless of where a particular user enters the app?
>
> So, in starting the app, I define these variables by visiting index.php.
> But if another user gets sent a url to, for example, the help page, when
> they visit it will those variables be available, or will I need to
> explicitly check on each to make sure the variables are defined, because
> the user entered at a different entry point than the 'normal' one?
>
> Note: I will probably do an explicit check anyway, since this seems more
> robust, but I ask to better understand how define works.
>
> Many thanks,
>
> M is for Murray

Well, there is no such thing as a "defined variable".  You are, I presume, 
talking about constants.  (That's what you get from define().)  A global 
constant (vis, not a class constant) is "super-global", that is, available 
absolutely everywhere after the line of code that defines it has executed.  

So if the user goes to index.php, and the first line defines a constant 
DEBUG_LEVEL, then that constant now exists anywhere in any function or method 
for the rest of that page request, period.

However, if someone goes to help.php then the line in index.php is never 
executed (why would it be, since the file was never included?), so the constant 
is not defined.

Does that make sense?

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Decorator with public methods

2008-12-26 Thread Larry Garfield
On Friday 26 December 2008 11:06:07 pm Nathan Nobbe wrote:

> to summarize, using your example above, i would most liely add doThings()
> to Baz, or create another decoration interface for doThings() if you plan
> on using the Bar implementation of doThings() in many places,
>
> interface G {
>   function doThings();
> }
>
> class Bar extends Decorator implements G {
>   function doThings() {
> // concreate implementation
>   }
> }
>
> class Baz implements F, G {
>   // recycle Bar::doThings()
>   public function doThings() {
> return $this->foo->doThings();
>   }
>   public function doOtherThings() {}
> }
>
> i appologize if this response is long winded, but im a big fan of the
> decorator, and ive actually got some pretty slick code in production in the
> photobucket code that uses the decorator pattern :D  it took about 2 months
> to code, and i leraned a lot about some of the practical aspects of
> decroration, specifically within the realm of php.  i know i repeated a few
> things there, but i felt it neccessary to better explain myself.
>
> -nathan

Thanks, Nathan.  Unfortunately, what you describe is impossible.  It requires 
me to know all the possible decorators ahead of time and implement the 
interface for each in each decorator, at which point I've gotten no benefit at 
all over just putting everything in the original base class in the first place. 
 
That defeats the purpose of decorators if I can't come up with a new one a 
month from now and not have to modify any of the existing code.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Decorator with public methods

2008-12-27 Thread Larry Garfield
On Saturday 27 December 2008 2:49:22 am Nathan Nobbe wrote:

> > Thanks, Nathan.  Unfortunately, what you describe is impossible.  It
> > requires
> > me to know all the possible decorators ahead of time and implement the
> > interface for each in each decorator, at which point I've gotten no
> > benefit at
> > all over just putting everything in the original base class in the first
> > place.
> > That defeats the purpose of decorators if I can't come up with a new one
> > a month from now and not have to modify any of the existing code.
>
> i see it more on a need-to-expose basis.  for example, why not, when
> presented w/ the current problem, just expose, Baz::doThings() now, b/c you
> know you need it in Baz instances ?  later if you find theres another
> method thats in Bar that isnt yet exposed, you just go in and add a similar
> wrapper for it in Baz at that time.  this is a typical flow in a layered
> architecture in my experience; often times controllers are revised to
> expose a new entry point for something on the backend that previously was
> unavailble from the front end, just as an example.

Because this is for a shipping application, not an in-house app where a month 
from now I can go back and adjust the interface for every class.  (It's open 
source, but still has a stable release version.)  I need to be able to add 
additional wrapping decorators *without* any modifications to the underlying 
object or its interfaces.  

As I said, the interface problem is solvable by having explicit delegating 
methods in the base decorator class and then only using __call() for nested 
decorators, which will be a much much smaller portion of the time.  It's the 
performance cost of __call() and the extra call stack layers that are my 
concern at the moment.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Architecture patterns in PHP

2008-12-27 Thread Larry Garfield
On Saturday 27 December 2008 6:57:18 pm Murray wrote:
> I'm interested in this topic as well. I'm starting out on a reasonably
> large web application, and I'm wondering at the best approach in PHP,
> particularly since it's been some years since I worked with PHP on a daily
> basis (the last 5 years have been purely C#).
>
> There's some dev community bias against using frameworks, isn't there? On
> one hand I'd love to take an approach that would make my end goal easier
> (thanks for pointing out Code Igniter, I'll look into it further), but on
> the other hand I'd rather avoid choices that 'tainted' (perhaps not the
> right word, but the best I could think of) the overall acceptance of the
> application once it's ready for release.
>
> So, currently I'm wondering about things like, 'Do I make an app that is a
> distinct page-per-function, or do I make an app that uses a monolithic
> index.php (similar to Wordpress?) and dynamically presents
> *everything*based on querystring values.'
>
> M is for Murray

There are exactly 47 architectural patterns, not a single more or less.  And 
if you believe that, I have a bridge you may be interested in. :-)

Seriously though, you'll probably find an existing implementation of any 
architectural pattern in PHP, including the ones that have absolutely no 
business being implemented in PHP.  (I include MVC in that, actually[1].)

If you really want to know about OO patterns, pick up the Gang-of-Four book[2] 
and spend some time wrapping your head around it.  (Warning: It is written 
mostly for a C++ audience, but it's still understandable.)  Then ignore those 
patterns that require more setup effort on each execution than they take to 
run, as those are ill-suited to PHP's shared-nothing architecture.  An active 
Observer, for instance, really sucks in a web app but a passive observer can 
do great things.

Then, get over your OO biases. :-)  PHP can do functions just as well as OO, 
and because of the setup costs in "proper" OO doing things with functions can 
often be much faster and require less mental overhead than building out a full 
OO setup.  There are plenty of major projects (PHP and otherwise) that use 
virtually no OO and still manage to kick ass.  (Drupal comes to mind, and the 
Linux kernel itself is all C code, which doesn't have syntactic OO.)  Don't 
assume that architecture just means OO.

Page-per-action vs. a front controller (the index.php to rule them all, 
usually with mod_rewrite) depends on your app and how you want to extend it.  
I personally far prefer a front controller approach as it means I can abstract 
out the bootstrap code and not even have the "include this at the top of every 
page" stuff.  It does mean you want mod_rewrite if your app is going to be at 
all bookmarkable or googleable (you may or may not want it to be), but that's 
not a huge requirement.

Disclaimer: I was asking this same question about 3-4 years ago, and started 
looking for PHP systems to study to learn from.  I found Drupal, started using 
it directly, and haven't left yet. :-)  That's probably not a bad approach to 
take.  Find an existing system that "feels right" to you and run with that.  
You'll almost certainly get a better system out of it than trying to write 
everything yourself.  (I've done that before, too, and it was generally a 
disaster.)

[1] http://www.garfieldtech.com/blog/mvc-vs-pac
[2] http://en.wikipedia.org/wiki/Gang_of_Four_(software)

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Re: Problem with fetching values...

2008-12-29 Thread Larry Garfield
On Monday 29 December 2008 2:26:46 am Michelle Konzack wrote:
> Am 2008-12-28 16:11:15, schrieb Nathan Nobbe:
> > OK.  i would stop right there and ask yourself why..  there are tons of
> > stable, working solutions out there that already do this, most notably
> > for php5, PDO,
> >
> > http://us.php.net/manual/en/pdo.drivers.php
> >
> > which btw, is written in C ;)
>
> I have tried to test it...
>
> The problem is now, that none of my 4 Hosting provider support it.  :-/

Then you seriously need new hosting providers.  PDO is part of the standard 
install for PHP5, and there is simply no excuse for a web host to not support 
it.  You can try contacting them first to ask them to enable it, and if they 
say no, you say "go away".  Really, that's simply irresponsible on their part.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Thank you everyone, What a wonderful world

2009-01-03 Thread Larry Garfield
On Saturday 03 January 2009 1:17:07 pm Dotan Cohen wrote:
> 2009/1/3 Behzad :
> > since you have modern weapons, equipped
> > with lasers!
>
> Did somebody say sharks with frigin' lasers?

No, but we have some ill-tempered sea-bass.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] old HTTP variables

2009-01-18 Thread Larry Garfield
On Sunday 18 January 2009 11:12:28 pm Ashley M. Kirchner wrote:
> Maybe I'm asking for trouble here, but, is there any way to make PHP
> 5.2.8 understand the old $HTTP variables?  Like:
>
> $HTTP_SESSION_VARS
> $HTTP_GET_VARS
> $HTTP_POST_VARS
> $HTTP_SESSION_VARS
> $HTTP_COOKIE_VARS
>
> etc., etc.
>
> I have an old application for which development has stopped back in
> 2004 ...  Should I give up now and install an earlier version of PHP
> (and somehow have it behave nice next to PHP5?
>
> -- A

http://us3.php.net/manual/en/ini.core.php#ini.register-long-arrays

Although you should probably take the time to upgrade the app anyway, as those 
variables are deprecated and won't be around forever.

-- 
Larry Garfield
la...@garfieldtech.com

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



[PHP] Doc standard for methods?

2009-01-26 Thread Larry Garfield
Greetings, all.  I am looking for feedback on a documentation question, in the 
hopes that someone else has found a good solution to an abnormal situation.

We're in the process of introducing OOP syntax to a large procedural code 
base.  Our developer base is a mixture of people who are procedural-centric 
and those that flip between procedural and OOP easily.  One area we've run into 
is documenting some of the more complex OOP interactions.  For example, if we 
have a method chain:

foo()->bar()->baz()->narf();

some developers have expressed concern in figuring out which narf() method is 
actually being called, since foo(), bar() and baz() may return objects of 
different classes (of the same interface) depending on various conditions (the 
classic factory pattern).  

Currently, we're including a docblock (Doxygen, close enough to PHPDoc for 
government work) on the interface or parent class that has full docs, and then 
nothing on the child classes.  My understanding of docblocks is that most 
documentation parsers prefer that, so that the docblock itself inherits.  

One suggestion that has been raised is to reference the parent class and 
factory function in a comment after the method signature.  That is:

class Narfing_mysql {
  // ...

 public function narf() { // Narfing  foo()
// ...
 }
}

So that it can be easily grepped for.  That strikes me as a very hacky non-
solution.  Does anyone else have a recommendation for how to improve such 
documentation?  Is there a standard in PHPDoc that I don't know about?  Any 
other projects doing something like that?

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] PHP Content Management

2009-01-29 Thread Larry Garfield
On Friday 30 January 2009 12:16:44 am Jason Todd Slack-Moehrle wrote:
> Hi All,
>
> I am looking for an open-sourced CMS that is PHP/MySQL based.
>
> I would like something simple to setup, but also would be good for a
> storefront as I want to use it for my indie business.
>
> Thoughts?
>
> -Jason

http://drupal.org/

I freely admit that the initial learning curve is a bit higher than we'd like, 
but you can still get very far without any PHP coding.  A custom look and feel 
unique to your site will, of course, require making a custom theme but if 
you're good with CSS that won't require much if any PHP either.  The payoff for 
the initial learning curve is a system that will scale and grow with you and 
your business almost indefinitely.  The community around it is also extremely 
supportive and there's a plethora of options for commercial development and 
support as well if you are so inclined.

For e-commerce, check out the "Ubercart" suite of modules:
http://drupal.org/project/ubercart

Disclaimer: I am a Drupal core developer and build sites with it 
professionally, so I am hardly an unbiased source. :-)

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] PHP Enclosing Tags? Do You Close Your PHP Declarations?

2009-02-02 Thread Larry Garfield

On Mon, 2 Feb 2009 08:23:49 +0100, Yannick Mortier  
wrote:
> 2009/2/2 Alpár Török :
>>
>>
>> 2009/2/1 Yannick Mortier 
>>>
>>> I once read that this is even recommended by the PHP developers... Has
>>> anyone got a quote for me about this?
>>>
>>
>> I know thw ZF codinf style includes it as a must. See here :
>>
>>
> http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html#coding-standard.php-file-formatting.general

The Drupal coding standards say to exclude the closing ?> on files for the same 
reason: It avoids a host of problems with whitespace handling and is just one 
less thing to have to deal with.

http://drupal.org/coding-standards

--Larry Garfield


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



Re: [PHP] DB Comparisons

2009-02-05 Thread Larry Garfield

On Thu, 05 Feb 2009 12:36:02 -0800, revDAVE  wrote:
> Hi Folks,
> 
> I¹m curious if there are any previous discussions / Articles / URL¹s
> that
> compare the power and scalability of MySQL (with php) with other
> technologies like MS sequel server oracle -  coldfusion etc
> 
> I imagine that most middleware like php / asp / coldfusion is relatively
> good & fast - (let me know if one is better ).  Mostly I¹m concerned with
> the speed and power of the backend database as to how it functions on an
> enterprise scale ­ such as how many hits it can handle per hour ­ how
> many
> users before it starts to slow down etc.

1) Define "enterprise scale".  The word "enterprise" has no useful meaning 
other than "your software isn't ready for it, therefore you suck". :-)

2) How well do you know your DB?  A well-tuned MySQL database will blow the 
crap out of a default config PostgreSQL server, but a well-tuned PostgreSQL 
server will wipe the floor with a badly configured mySQL database.  Your 
knowledge of the underlying tool and how to get the most out of it will matter 
more than which vendor you go with, unless there are very specific features you 
require.

--Larry Garfield


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



Re: [PHP] PHP OOP

2009-02-09 Thread Larry Garfield
On Monday 09 February 2009 10:02:37 am tedd wrote:
> Hi gang:
>
> At the college where I teach, they are considering teaching OOP, but
> they don't want to settle on a specific language.
>
> My thoughts are it's difficult to teach OOP without a language --
> while the general concepts of OOP are interesting, people need to see
> how concepts are applied to understand how they work -- thus I think
> a specific language is required
>
> I lean toward C++ because I wrote in it for a few years AND C++
> appears to be the most common, widespread, and popular OOP language.
>
> However, while I don't know PHP OOP, I am open to considering it
> because of the proliferation of web based applications. My personal
> opinion is that's where all programming is headed anyway, but that's
> just my opinion.
>
> With that said, what's the differences and advantages/disadvantages
> between C++ and PHP OOP?
>
> Cheers,
>
> tedd

I definitely agree that teaching OOP without a language to write it in is a 
very stupid idea.  However, part of the problem is that there is in practice 
no one version of OOP.

Java is probably the best example of academically pure "classic OOP" (that is, 
class-based).  That can be good for teaching, but it can also suck for 
developing because you have to do things in an academically formal way.

Javascript, on the other hand, is a prototype-based language.  Technically 
that's also OOP, or can be, but the code is entirely different conceptually 
when functions, methods, objects, and classes are all the same thing. :-)

PHP's OOP is very closely modeled on Java's, but with some interesting 
additions.  PHP 5.3 adds a few more and 5.4/6.0 is likely to add traits, which 
are another animal entirely.  PHP is also a hybrid language and, by nature of 
being a shared-nothing scripting language OOP is often the wrong choice 
because of the setup and initialization costs.

C++ has "a little of each", albeit in a frequently convoluted way.  It also 
has about 30 more types of access control than any other language I know, for 
better or worse.

LISP is its own creature, closer to Javascript than to anything else I just 
mentioned.  (Or arguably Javascript is closer to LISP.)

Personally, I recommend teaching programming first in C++.  Force them to do 
the hard stuff so they appreciate what the runtime is doing for them in higher 
level languages.  It also means you can teach procedural and OOP in the same 
syntax.  Then once they've gotten a few bruises in C++, expose them to Java, 
Javascript, PHP, etc. to let them see what higher level work actually gets 
done in these days.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Re: PHP includes

2009-03-09 Thread Larry Garfield
On Monday 09 March 2009 3:07:17 pm Nathan Rixham wrote:
> Ashley Sheridan wrote:
> > Just thought I'd point out that it's recommended against giving non-php
> > extensions to PHP code pages. Basically, making all of your include
> > files .inc without the server correctly configured to recognise all .inc
> > files as PHP files, you are opening yourself up to possible hacks where
> > people put the URL of your include directly in their browser and view
> > all your code. Best thing is usually to name files like this:
> > filename.inc.php or some-such, and not filename.inc.
>
> v well said - one thing you never want is your source showing!

Unless you're working in open source and then the source is showing anyway 
from the original download site.  And if simply knowing your source code is a 
security hole, then you have bad software.

Your config file with passwords and such, sure, keep that locked down tight.  
But don't rely on security through obscurity.

-- 
Larry Garfield
la...@garfieldtech.com

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



[PHP] Too many open files

2009-04-05 Thread Larry Garfield
I've a site on a shared host that is for the most part working well.  However, 
more recently I've started getting the following error:

failed to open stream: Too many open files in system in  on line 
.

When it happens it will happen to everyone for a short period, and then stop.  
There does not seem to be much if any functionality failure when that error 
appears (I am just seeing the error in my application logs so I can't be 
sure), but it is still highly annoying and worrisome.  The number of files used 
by my application has not changed in months, however.

I know PHP has a max-files-open limit somewhere.  Is that per process, per 
user, or per server?  Is this even something I can address myself in my app, 
or does it indicate that the server itself is getting over-busy and I have to 
just beg my web host for a less busy server?  Any other thoughts as to how to 
respond?

Cheers.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Re: PHP6 return by reference deprecation

2009-05-02 Thread Larry Garfield
On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
> 'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
> > If this is going away, how do you return things by reference, so as to
> > ensure a single copy of something (yes, I know the singleton pattern can
> > be used; I do use it as well; it's more complicated)?
>
> You'll want to use the Singleton design pattern here.
>
> Let's say you're config object is a class.

That's well and good if the thing you want a single copy of is an object.  The 
way objects pass in PHP 5 makes singletons easy.  But I actually just 
developed a system for PHP 5.2 that includes a class that deliberately allows 
a caller to reach in and grab an internal array-based data structure for 
special cases.

class Foo {
  protected $internalConfig = array(...);

  public function &getConfig() {
return $this->internalConfig;
  }
}

$foo = new Foo();
...
$config = &$foo->getConfig();
// Do stuff to $config that wouldn't make sense to do via methods.

So do I understand the OP correctly that is going to break with PHP 6 now?  I 
certainly hope not, as that would be incredibly short sighted and stupid.  
There are plenty of use cases for returning by reference besides making PHP 4 
objects behave correctly.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Re: PHP6 return by reference deprecation

2009-05-02 Thread Larry Garfield
On Saturday 02 May 2009 3:20:24 pm Colin Guthrie wrote:
> 'Twas brillig, and Larry Garfield at 02/05/09 20:00 did gyre and gimble:
> > On Saturday 02 May 2009 9:30:09 am Colin Guthrie wrote:
> >> 'Twas brillig, and Paul M Foster at 02/05/09 06:07 did gyre and gimble:
> >>> If this is going away, how do you return things by reference, so as to
> >>> ensure a single copy of something (yes, I know the singleton pattern
> >>> can be used; I do use it as well; it's more complicated)?
> >>
> >> You'll want to use the Singleton design pattern here.
> >>
> >> Let's say you're config object is a class.
> >
> > That's well and good if the thing you want a single copy of is an object.
> >  The way objects pass in PHP 5 makes singletons easy.  But I actually
> > just developed a system for PHP 5.2 that includes a class that
> > deliberately allows a caller to reach in and grab an internal array-based
> > data structure for special cases.
> >
> > class Foo {
> >   protected $internalConfig = array(...);
> >
> >   public function &getConfig() {
> > return $this->internalConfig;
> >   }
> > }
> >
> > $foo = new Foo();
> > ...
> > $config = &$foo->getConfig();
> > // Do stuff to $config that wouldn't make sense to do via methods.
> >
> > So do I understand the OP correctly that is going to break with PHP 6
> > now?  I certainly hope not, as that would be incredibly short sighted and
> > stupid. There are plenty of use cases for returning by reference besides
> > making PHP 4 objects behave correctly.
>
> Use ArrayObject rather than just array. e.g.
>
> class Foo {
>protected $internalConfig;
>
>public function __construct() {
>  $this->internalConfig = new ArrayObject(...);
>}
>
>public function getConfig() {
>  return $this->internalConfig;
>}
> }
>
> http://www.php.net/manual/en/class.arrayobject.php
>
> Col

If it were just a simple one level array, sure.  But it's not.  It's actually 
quite deep and complex.  (That's why exposing it is a better plan than just 
offering an accessor.)

ArrayAccess is also dramatically slower than regular arrays:
http://www.garfieldtech.com/blog/magic-benchmarks

So forcing everything through an object is still pointless and a performance 
loss.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Web application design considerations - a good reference ?

2009-06-01 Thread Larry Garfield
Do not under any circumstances try to do this from scratch. :-)  Use an 
existing framework like Zend Framework or CakePHP or a CMS/framework hybrid 
like Drupal or a dedicated app for billing and processing.  It will save you 
months of work, and countless security holes.  

Even if you don't use it directly, studying a large existing system like that 
will open your mind to better ways of thinking.  I only half-joke when I say 
that everything I know about PHP I learned from Drupal. :-)

On Monday 01 June 2009 11:50:36 pm Angus Mann wrote:
> Hi all.
>
> I'm working on a PHP project for my own personal business use. It will
> handle billing and invoices as well as payments and time management,
> bookings, appointments and a few more. I may add things like personal
> messaging between the various users and a customer login to check on the
> progress of their accounts.
>
> It is a big project and will probably take a year or so to complete in my
> spare time.
>
> I have made a couple of starts but I have no experience in creating such
> large applications and I find I often end up with spaghetti code. I've
> tried using session variables to keep track of where and what the program
> is doing but there are so many permuations and combinations I found myself
> writing endless streams of if's, and's and or's just to figure out what
> page to display.
>
> The code is not the probblem for me...it's the flow and organization of the
> code.
>
> Can anybody point me to a good book or tutorial that lays down the
> principles and gives some suggestions for integrating the many subroutines
> of a large application? I want to make the code readable and logical in its
> flow, and avoid repetition of code segments.
>
> Much appreciated.
> Angus

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] php applications

2009-06-08 Thread Larry Garfield
On Monday 08 June 2009 12:34:40 pm Robert Cummings wrote:
> Matty Sarro wrote:
> > Real men use perl ;)
>
> When I was younger my dad told me real men drink their coffee black... I
> tried it for a month and then I told him real men choose their own path
> in life.
>
> Cheers,
> Rob.

Mind if I use that quote elsewhere (credited if you prefer)?

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] PHP programming strategy

2009-08-01 Thread Larry Garfield
On Saturday 01 August 2009 8:25:40 pm Clancy wrote:
> Is anyone here interested in discussing programming strategy, or or know of
> a discussion group which is interested in the subject?
>
> The sorts of questions I am interested in are:
>
> 1. I have a highly variable program which always shows the same page, but
> which includes different modules to give different results.  The various
> modules call on different functions. Is it better to minimise memory by
> including only the functions actually required, but increase the number of
> files included, or to bundle all the functions into one file, thereby
> reducing the number of files included but increasing the size in memory?

That depends greatly on your usage patterns.  Does your application make lots 
of "sideways" calls to integrate different modules, or is just "switch on a GET 
parameter, run this function, done"?  If the latter, then lazy-loading just 
the one or two files you want is probably better.  If the former, you'd need a 
lot of interesting logic to make lazy-loading work well enough to be justified. 
 
(I've been working on such a system for Drupal for the past year, and it's not 
easy to get right because there can be a fair bit of overhead.)

If your application is heavily OOP then PHP supports dynamic autoloading of 
classes, which can greatly simplify your code logic but at the same time the 
autoload mechanism itself is not free either.

The age of the computer matters, too.  Modern hard drives are faster than they 
used to be, and more recent OS versions can do some fairly aggressive caching 
if the files you're reading all fit inside the OS cache somewhere in memory so 
you may not actually hit disk to "load" each of your files.

> 2. As PHP is an interpreted program comments certainly increase the memory
> requirements, and presumably they slow down the operation of the program.
> Would stripping out the comments before uploading the production version
> give any visible improvement in performance?

I actually benchmarked that once.  I had a reasonably large PHP file that was, 
in fact, over 50% docblocks.  That's not even counting inline comments.  While 
trying to find things to optimize, removing about 800 lines worth of comments 
(all of the docblocks) did, in fact, produce a noticeable performance 
difference.  It was only barely noticeable, but it just barely registered as 
more than random sampling jitter.  I actually concluded that if cutting the 
file *in half* was only just barely noticeable, then it really wasn't worth the 
effort.

Just install an opcode cache.  That will take care of most of your memory 
issues. :-)

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] PHP programming strategy

2009-08-02 Thread Larry Garfield
On Saturday 01 August 2009 11:01:11 pm Eddie Drapkin wrote:
> > I actually benchmarked that once.  I had a reasonably large PHP file that
> > was, in fact, over 50% docblocks.  That's not even counting inline
> > comments.  While trying to find things to optimize, removing about 800
> > lines worth of comments (all of the docblocks) did, in fact, produce a
> > noticeable performance difference.  It was only barely noticeable, but it
> > just barely registered as more than random sampling jitter.  I actually
> > concluded that if cutting the file *in half* was only just barely
> > noticeable, then it really wasn't worth the effort.
>
> Yeah but what happens if you run the script through the tokenizer and
> strip ALL comments, unnecessary whitespace, newline characters, etc.
> out?

Honestly?  I think you'll save more CPU time by eliminating one SQL query.  
Most files are not 60% comments.  In a file that is only about 20% comments, I 
doubt you could even measure the difference.  There are far far far more useful 
ways to optimize your code.

(Note that this is different for CSS or Javascript, where compressors like that 
are commonplace because you have to transfer the entire file over the network 
repeatedly, which is a few orders of magnitude slower than system memory.  
Compressors and aggregators there make sense.  PHP code never leaves the 
server, so those benefits don't exist.)

-- 
Larry Garfield
la...@garfieldtech.com

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



[PHP] ODBC and long text fields

2007-01-07 Thread Larry Garfield
Hi all.  I've a question regarding PHP's ODBC support.

Here's the situation: 

We've a PHP app that uses ODBC to talk to a MS SQL server.  Its original home 
was on a server that used the OpenLink ODBC driver, which was a POS, so we 
build an abstraction wrapper around the subset of PHP's ODBC functions that 
we were able to use to make it usable.  The internal code for a query is 
built on odbc_exec, odbc_fetch_row, and odbc_result.  The main interesting 
part is that the original driver didn't allow for named results, so instead 
we have a small string parser that reads the incoming SQL query, extracts the 
field names, and then uses that to map the numeric result indexes to their 
field name.  Kinda clunky, but worked well and used only a minimal ODBC 
footprint.  

That worked fine on their old system.  However, the client then moved from a 
Windows IIS server to Apache and PHP 5.1.6 on a Linux box, but still talking 
to an MS SQL server on a Windows box.  We migrated our test environment to 
the same; Linux/Apache/PHP 5.1 talking to MS SQL on a Windows box over the 
network.  Our system uses the unix_ODBC and freetds stack for ODBC 
connectivity, and that works fine.

On the client's system, it works fine except for a few odd cases.  
Specifically, on a few queries that pull data from large text fields the 
query may hang.  It seems to reliably hang on certain records only, and only 
after those records have been edited.  It seems that when updating a record, 
there is a small chance of something happening to that record and it then not 
working thereafter.  A PHP test script run from the command line freezes, 
while the same query run directly on the SQL server returns almost instantly.

The client has been in contact with their ODBC driver vendor (they're using a 
commercial driver), and the vendor's response is that we're not using ODBC 
correctly.  Specifically, they say:

-
I followed the ODBC calls in your odbc trace file and I got error 
"Invalid Descriptor Index" on SQLGetData as well. I know we normally 
don't handle the retrieval of large dataset like Text using SQLGetData 
as your application is doing. I'm in the research of whether the way 
your application does is valid or not.
-

They then followed up with:

-
We have done some research on this issue. We realized that your 
application is binding all the columns for the resultset and then use 
SQLGetData. This is not the correct way to do. You can either use bind 
column for result set and then print out the data in the bound buffer, 
or use SQLGetData to get the unbound resultset.
-

They then include some sample code that is all in C.

Now I'll be honest and say I don't quite follow what they're talking about. I 
do not claim to be an ODBC guru, but SQLGetData is a lower-level operation, 
SQL level or C level I don't know, but not something that happens in PHP code 
as far as I am aware.  Are they saying there's a bug in PHP's 
odbc_fetch_row()?  Or is it a bug in their driver if it can't handle whatever 
it is odbc_fetch_row() does internally?  Or should we be using odbc_result() 
instead of odbc_fetch_row() if we're dealing with a text field rather than a 
varchar or int?  

I am confused, and would appreciate assistance in becoming less confused. :-)  
Thanks.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] ODBC and long text fields

2007-01-07 Thread Larry Garfield
On Sunday 07 January 2007 8:26 pm, Jochem Maas wrote:

> > Now I'll be honest and say I don't quite follow what they're talking
> > about. I do not claim to be an ODBC guru, but SQLGetData is a lower-level
> > operation, SQL level or C level I don't know, but not something that
> > happens in PHP code as far as I am aware.  Are they saying there's a bug
> > in PHP's
> > odbc_fetch_row()?  Or is it a bug in their driver if it can't handle
> > whatever it is odbc_fetch_row() does internally?
> > Or should we be using odbc_result()
> > instead of odbc_fetch_row() if we're dealing with a text field rather
> > than a varchar or int?
>
> the way I read it odbc_result() is just an alternative way of doing what
> you do with odbc_fetch_row() - I can't see any reason why doing it with
> odbc_result() would suddenly make it work - nonetheless it might be worth
> trying it just to rule it out.
>
> with regard to wanting results returned in a 'named' fashion, does the new
> setup still not allow use of odbc_fetch_array() instead of
> odbc_fetch_row()? not that I see any logic in that solving the issue, again
> it might be worth trying to see if it does.

Honestly I've not tried.  (I also don't have the wrapper code in front of me 
at the moment. )  That could be a nice thing to simplify for performance, 
but I suspect that if the problem is with odbc_fetch_row() then 
odbc_fetch_array() will have the same bug.

> I don't know much about MSSQL, or whether 'text' is an actual field type,
> but maybe this function offers a wayout?:
>
>   http://php.net/manual/en/function.odbc-binmode.php

No, that looks like it's for binary data.  "Text" is a MS SQL field for 
huge-ass text fields, essentially similar to the MySQL field of the same name 
(at least at an API level).  We also tried playing with odbc_longreadlen() 
and setting MS SQL's TEXTSIZE and TEXTLENGTH parameters to no avail.

> are the php versions on the 2 systems you mention exactly the same? (you
> mention 5.1 and 5.1.6) this could be a clue to the problem.

It's either both 5.1.6 or 5.1.6 live and 5.1.4 devel.  (I don't recall what 
our exact version is atm.)  We're in the process of upgrading our server 
soon, and I'm not sure what it will have.  Probably 5.2, just to keep life 
interesting. :-)

> lastly I don't suppose that it possible for you to switch to using the
> MSSQL specific php extension? [http://php.net/mssql] it might offer a
> better/faster connection to the MSSQL server as well as making the issue go
> away.

I don't believe the client allows direct MSSQL connections.  Besides, the 
MSSQL functions still require an ODBC driver underneath, so if the problem is 
with the ODBC driver then that won't change anything.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] multidimensional array problems

2007-01-13 Thread Larry Garfield
It's better to just leave the record as an array and read it that way.

while ($row = mysql_fetch_assoc($result)) {
print "{$row['game']} {$row['type']}\n";
}

And so on.  You're not actually dealing with a multi-dimensional array yet; 
$result is an object from which you are extracting data records as 
one-dimensional associative arrays.

On Saturday 13 January 2007 7:40 pm, nitrox doe wrote:
> hi all,
> im very new to php but i think i jumped on the
> toughest thing to learn. Im trying to create a
> team roster that will show game, game type
> and league and then show each member based
> on the game type. Ive worked out alot of code
> but just cant figure where im going wrong. so
> here is my code. Any pointers would be greatly
> appreciated.
>
> this is an example of what im trying to do
> http://www.chalkthree.com/exampleroster.html
>
> php code
>  //begin member league table
> $memroster = "SELECT inf_league.game, inf_league.type,
> inf_member.user_name, inf_member.rank, " .
>  "inf_member.country, inf_member.email " .
>  "FROM inf_league " .
>  "INNER JOIN inf_memberleague ON inf_league.gid =
> inf_memberleague.l_id " .
>  "INNER JOIN inf_member ON inf_member.user_id =
> inf_memberleague.m_id";
> $memrosterresults = mysql_query($memroster)
>   or die(mysql_error());
>   while ($row = mysql_fetch_array($memrosterresults)) {
>
> foreach ($row as $game => $type) {
> echo "";
> echo "$type";
>   foreach ($row as $type => $user_name) {
> echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " .
> "$email"; }
> print '';
> }
> }
> //end member league table
> ?>
>
>
>
>
>
>
>
>
> mysql
>
>
> CREATE TABLE `inf_league` (  `gid` int(11) NOT NULL auto_increment,  `game`
> varchar(255) NOT NULL,  `type` varchar(255) NOT NULL,  `league`
> varchar(255) NOT NULL,  `season` varchar(255) NOT NULL,  PRIMARY KEY 
> (`gid`))
> TYPE=MyISAM  AUTO_INCREMENT=4 ;-- -- Dumping data for table `inf_league`--
> INSERT INTO `inf_league` (`gid`, `game`, `type`, `league`, `season`) VALUES
> (1, 'DF:BHD', 'TKOTH', 'TWL', '2006 1st Quarter');INSERT INTO `inf_league`
> (`gid`, `game`, `type`, `league`, `season`) VALUES (2, 'CoD2', 'CTF',
> 'TWL', '2006 2nd QTR');INSERT INTO `inf_league` (`gid`, `game`, `type`,
> `league`, `season`) VALUES (3, 'CoD2', 'Search & Destroy', 'CAL', '2006 4th
> QTR');-- -- --
> Table structure for table
> `inf_member`-- CREATE TABLE `inf_member` (  `user_id` int(11) NOT NULL
> auto_increment,  `user_level` int(2) NOT NULL default '0',  `list_order`
> int(3) NOT NULL default '0',  `user_name` varchar(100) NOT NULL default '',
> `password` varchar(25) NOT NULL default '',  `email` varchar(100) NOT NULL
> default '',  `country` text NOT NULL,  `game` text,  `rank` varchar(40)
> default NULL,  `qoute` longtext,  `config` int(1) default '0',  `map`
> varchar(100) default '',  `gun` varchar(100) default '',  `brand`
> varchar(100) default '',  `cpu` varchar(20) default '',  `ram` varchar(20)
> default '',  `video` varchar(100) default '',  `sound` varchar(100) default
> '',  `monitor` varchar(100) default '',  `mouse` varchar(100) default '',
> PRIMARY KEY  (`user_id`)) TYPE=MyISAM  AUTO_INCREMENT=3 ;--
> -- Dumping data for table `inf_member`-- INSERT INTO `inf_member`
> (`user_id`, `user_level`, `list_order`, `user_name`, `password`, `email`,
> `country`, `game`, `rank`, `qoute`, `config`, `map`, `gun`, `brand`, `cpu`,
> `ram`, `video`, `sound`, `monitor`, `mouse`) VALUES (1, 1, 0, 'nitrox',
> 'test', '[EMAIL PROTECTED]', 'United States', 'CoD2', 'Founder', NULL, 0, 
> NULL,
> NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);INSERT INTO `inf_member`
> (`user_id`, `user_level`, `list_order`, `user_name`, `password`, `email`,
> `country`, `game`, `rank`, `qoute`, `config`, `map`, `gun`, `brand`, `cpu`,
> `ram`, `video`, `sound`, `monitor`, `mouse`) VALUES (2, 1, 1, 'raze',
> 'itsme', '[EMAIL PROTECTED]', 'United States', NULL, 'Leader', NULL, 0, '',
> '', '', '', '', '', '', '', '');--
> -

Re: [PHP] multidimensional array problems

2007-01-13 Thread Larry Garfield
Copying back to the list...

Actually, I'd suggest doing a PHP-side grouping.  See this article for 
details:

http://www.garfieldtech.com/blog/php-group-by

On Saturday 13 January 2007 10:50 pm, nitrox . wrote:
> I hope this is returning to the mail list so all can read.
> Thanks for the reply Larry, i appreciate your time spent to reply to me. If
> i print the way your showing it prints for every instance. Im trying to
> create a team roster like the following url shows:
> http://www.chalkthree.com/exampleroster.html
>
> I have 3 tables in my db, league table, lookup table and member table. Do
> you think it would be better possably to do seperate querys and then match
> them in php? would that be possable the given the setup i have?
>
> >From: Larry Garfield <[EMAIL PROTECTED]>
> >To: php-general@lists.php.net
> >Subject: Re: [PHP] multidimensional array problems
> >Date: Sat, 13 Jan 2007 21:51:08 -0600
> >
> >It's better to just leave the record as an array and read it that way.
> >
> >while ($row = mysql_fetch_assoc($result)) {
> >print "{$row['game']} {$row['type']}\n";
> >}
> >
> >And so on.  You're not actually dealing with a multi-dimensional array
> > yet; $result is an object from which you are extracting data records as
> > one-dimensional associative arrays.
> >
> >On Saturday 13 January 2007 7:40 pm, nitrox doe wrote:
> > > hi all,
> > > im very new to php but i think i jumped on the
> > > toughest thing to learn. Im trying to create a
> > > team roster that will show game, game type
> > > and league and then show each member based
> > > on the game type. Ive worked out alot of code
> > > but just cant figure where im going wrong. so
> > > here is my code. Any pointers would be greatly
> > > appreciated.
> > >
> > > this is an example of what im trying to do
> > > http://www.chalkthree.com/exampleroster.html
> > >
> > > php code
> > >  > > //begin member league table
> > > $memroster = "SELECT inf_league.game, inf_league.type,
> > > inf_member.user_name, inf_member.rank, " .
> > >  "inf_member.country, inf_member.email " .
> > >  "FROM inf_league " .
> > >  "INNER JOIN inf_memberleague ON inf_league.gid =
> > > inf_memberleague.l_id " .
> > >  "INNER JOIN inf_member ON inf_member.user_id =
> > > inf_memberleague.m_id";
> > > $memrosterresults = mysql_query($memroster)
> > >   or die(mysql_error());
> > >   while ($row = mysql_fetch_array($memrosterresults)) {
> > >
> > > foreach ($row as $game => $type) {
> > > echo "";
> > > echo "$type";
> > >   foreach ($row as $type => $user_name) {
> > > echo "$user_name" . " - " . "$rank" . " - " . "$country" . " - " .
> > > "$email"; }
> > > print '';
> > > }
> > > }
> > > //end member league table
> > > ?>
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > mysql
> > >
> > >
> > > CREATE TABLE `inf_league` (  `gid` int(11) NOT NULL auto_increment,
> >
> >`game`
> >
> > > varchar(255) NOT NULL,  `type` varchar(255) NOT NULL,  `league`
> > > varchar(255) NOT NULL,  `season` varchar(255) NOT NULL,  PRIMARY KEY
> > > (`gid`))
> > > TYPE=MyISAM  AUTO_INCREMENT=4 ;-- -- Dumping data for table
> >
> >`inf_league`--
> >
> > > INSERT INTO `inf_league` (`gid`, `game`, `type`, `league`, `season`)
> >
> >VALUES
> >
> > > (1, 'DF:BHD', 'TKOTH', 'TWL', '2006 1st Quarter');INSERT INTO
> >
> >`inf_league`
> >
> > > (`gid`, `game`, `type`, `league`, `season`) VALUES (2, 'CoD2', 'CTF',
> > > 'TWL', '2006 2nd QTR');INSERT INTO `inf_league` (`gid`, `game`, `type`,
> > > `league`, `season`) VALUES (3, 'CoD2', 'Search & Destroy', 'CAL', '2006
> >
> >4th
> >
> > > QTR');-- -- --
> > > Table structure for table
> > > `inf_member`-- CREATE TABLE `inf_member` (  `user_id` int(11) NOT NULL
> > > auto_increment,  `user_level` int(2) NOT NULL default '0', 
>

Re: [PHP] Stripslashes

2007-01-13 Thread Larry Garfield
On Sunday 14 January 2007 12:01 am, Jim Lucas wrote:

> This is what I use, and it has worked ever time.
>
> if ( get_magic_quotes_gpc() ) {
>   $_POST = array_map("stripslashes", $_POST);
> }
>
> Jim Lucas

That will break as soon as you submit an array back through a POST request, 
which I do rather often. :-)  You need to iterate over the array, and if an 
item is an array, iterate over it recursively.  array_walk() can be useful 
here.

Of course, the real answer is to disable magic quotes in the first place as 
they are spawn of Satan.  If you're using a web host that doesn't let you do 
so, get a real web host.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Stripslashes

2007-01-14 Thread Larry Garfield
On a real web host, they'll let you have a .htaccess file where you can 
disable them like so:

php_value magic_quotes_gpc 0

(I keep saying "real web host" because I've just recently had to deal with a 
few web hosts that a client insisted on that didn't have a standard 
configuration and didn't support .htaccess files.  I lost 6 hours of my life 
right before Christmas trying to work around that fact, and I can't get them 
back.  If you find yourself in the same situation, vote with your feet and 
let such hosts die a horrible and bankrupt death.)

On Sunday 14 January 2007 10:46 am, Beauford wrote:
> I just turned  off get_magic_quotes in my PHP.ini, but not sure if the
> hosting company has it on or not once I upload the site.
>
> > -Original Message-
> > From: Beauford [mailto:[EMAIL PROTECTED]
> > Sent: January 14, 2007 11:34 AM
> > To: 'PHP'
> > Subject: RE: [PHP] Stripslashes
> >
> >
> > I guess I'm just doing something wrong, 'cause that doesn't
> > work either - nor do the hundreds of other snippets I've used.
> >
> > Here's the scenario. I have a form - after they submit the
> > form it shows what they have entered, this is where I get the
> > \. It also does it if the form redisplays after the user has
> > input invalid data.
> >
> > All this is being done on the same page.
> >
> > > -Original Message-
> > > From: Jim Lucas [mailto:[EMAIL PROTECTED]
> > > Sent: January 14, 2007 1:02 AM
> > > To: Beauford
> > > Cc: PHP
> > > Subject: Re: [PHP] Stripslashes
> > >
> > > Beauford wrote:
> > > > Hi,
> > > >
> > > > Anyone know how I can strip slashes from $_POST variables. I have
> > > > tried about a hundred different ways of doing this and
> > >
> > > nothing works.
> > >
> > > > i.e.
> > > >
> > > > if(!empty($_POST)){
> > > > foreach($_POST as $x => $y){
> > > > $_POST[$x] = stripslashes($y);
> > > > }
> > > > }
> > > >
> > > > This came about after someone tried to enter O'Toole in a
> > >
> > > form, and it
> > >
> > > > appeared as O\'Toole.
> > > >
> > > > Thanks
> > >
> > > This is what I use, and it has worked ever time.
> > >
> > > if ( get_magic_quotes_gpc() ) {
> > >   $_POST = array_map("stripslashes", $_POST); }
> > >
> > > Jim Lucas
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To
> > unsubscribe, visit: http://www.php.net/unsub.php

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Stripslashes

2007-01-14 Thread Larry Garfield
Copying this back on list where it belongs...

If the apache process on the server is configured to support .htaccess files, 
then there shouldn't be anything special you need to do.  Do you have any 
other htaccess directives in use that could be affecting it?  Remember that 
it's not "htaccess", it's a ".htaccess" file.  Mind the period.


On Sunday 14 January 2007 9:56 pm, Beauford wrote:
> Hi Larry,
>
> I'm sending this off list. I put this in the .htaccess file on the hosting
> server, but still have the same problems. Is there a special way this needs
> to be done?
>
> Thanks
>
> > Thanks
> >
> > > -Original Message-
> > > From: Larry Garfield [mailto:[EMAIL PROTECTED]
> > > Sent: January 14, 2007 4:39 PM
> > > To: php-general@lists.php.net
> > > Subject: Re: [PHP] Stripslashes
> > >
> > > On a real web host, they'll let you have a .htaccess file where you
> > > can disable them like so:
> > >
> > > php_value magic_quotes_gpc 0
> > >
> > > (I keep saying "real web host" because I've just recently
> >
> > had to deal
> >
> > > with a few web hosts that a client insisted on that didn't have a
> > > standard configuration and didn't support .htaccess files.
> >
> > I lost 6
> >
> > > hours of my life right before Christmas trying to work around that
> > > fact, and I can't get them back.  If you find yourself in the same
> > > situation, vote with your feet and let such hosts die a
> >
> > horrible and
> >
> > > bankrupt death.)
> > >
> > > On Sunday 14 January 2007 10:46 am, Beauford wrote:
> > > > I just turned  off get_magic_quotes in my PHP.ini, but not
> > >
> > > sure if the
> > >
> > > > hosting company has it on or not once I upload the site.


-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Mailing list combined with PHP based forum

2007-01-15 Thread Larry Garfield
The closest I know of to that would be to use Drupal[1] with the Organic 
Groups[2] module and the og2list[3] module.  You also need an MTA, of course.

Disclaimer: I've not actually set up such a system.  I've just seen it 
discussed as a reasonable facsimile.  See the Drupal Groups[4] site for 
Organic Groups in action.

[1] http://drupal.org/
[2] http://drupal.org/project/og
[3] http://drupal.org/project/og2list
[4] http://groups.drupal.org/

On Monday 15 January 2007 8:27 pm, Dave M G wrote:
> PHP Users,
>
> I'm creating a PHP based forum, and what I'd like to do is have it work
> so that people can view and read the information via email, just like a
> mailing list.
>
> Yahoo! Groups does this, so I know this sort of thing is possible in
> principle.
>
> But so far as I can tell, open source PHP based forums, like phpBB and
> Simple Machines, don't commonly have this feature. Perhaps it's not
> possible with PHP?
>
> I would imagine this is accomplished with a Cron job that checks an
> email account and passes the messages to the PHP system for parsing into
> the forum.
>
> Can anyone start me off with some tips as to how, and if, this might be
> possible?
>
> Thanks for any advice or informaiton.
>
> --
> Dave M G
> Ubuntu 6.06 LTS
> Kernel 2.6.17.7
> Pentium D Dual Core Processor
> PHP 5, MySQL 5, Apache 2

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] What makes a PHP expert

2007-01-19 Thread Larry Garfield
I'd say a "programming expert" is one that can grasp the nuances and 
complexities of a problem and break it down coherently and correctly in a 
relatively short amount of time (compared to "average").  

A "php expert" is one that can break it down and implement a solution that 
leverages the "PHP way" of doing things and works with the language for a 
truly elegant solution.  (The "PHP way" of solving a problem is different 
than the "Java way" is different from the "C++ way".  Different languages 
have different strengths.  A language expert knows how to play to the 
strengths of the language he's using.)

On Thursday 18 January 2007 9:23 am, bruce wrote:
> hi...
>
> for my $0.02 worth... sometimes it's as simple as someone who can qucikly
> grasp the issue(s) and nuances/intracacies of the issues/problems, and who
> can then utilize php to solve the problem, as well as craft an elegant
> solution that will scale into the future.
>
> peace...
>
>
> -Original Message-
> From: Jay Blanchard [mailto:[EMAIL PROTECTED]
> Sent: Thursday, January 18, 2007 5:56 AM
> To: h; php-general@lists.php.net
> Subject: RE: [PHP] What makes a PHP expert
>
>
> [snip]
> I often see job ads asking for a PHP expert and was wandering what you
> all thought makes a PHP programmer into an expert.
>
> what would you mark out as the key skills that distinguishes an expert
> from the ordinary i.e. OOP mastery, regular expressions etc.
> [/snip]
>
> First I would consider number of years of programming experience
> including how many years a programmer had been using PHP. I would
> examine some code and look for organization, documentation, and
> consistency. Is the programmer published (articles, books, etc) which
> may not count against expertise?
>
> An expert encompasses so much more than skills. For instance, I could be
> an expert on football because I understand history of the game, have
> been published, understand game planning and execution, and have played
> at the wide receiver position. Only the last 2 items really require
> skills.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] What makes a PHP expert

2007-01-19 Thread Larry Garfield
True, there's rarely One True Answer.  That's one reason why there is no 
clear-cut definition of "Expert".  However, there are frequently better or 
worse solutions to a problem.  It's easier to pinpoint when someone is not 
going with the grain of the language than when they are.  

For instance, considering the global namespace to be a good interface between 
system components disqualifies someone from the expert title, IMO. :-)  (Yes, 
I've had to clean up after that.)  Using arrays but never actually using 
associative arrays is another "against the grain" issue in PHP (whereas in 
other languages associative arrays are not as dead-easy as in PHP, so they're 
a wrong answer more often).  That doesn't automatically mean that using 
associative arrays and not using the global namespace make someone an expert, 
of course, it's just an indication that they don't not know what they're 
doing.

On Friday 19 January 2007 9:43 am, bruce wrote:
> larry...
>
> sounds good... however, given that you often have a myriad of different
> ways to solve a problem, how does on determine which of the solutions, is
> the 'PHP way'
>
> unless there are seriously obvious flaws with an approach, you can often
> have different approaches of solving a problem that pretty much lead to the
> same result..
>
> peace...
>
>
>
> -Original Message-
> From: Larry Garfield [mailto:[EMAIL PROTECTED]
> Sent: Friday, January 19, 2007 7:29 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] What makes a PHP expert
>
>
> I'd say a "programming expert" is one that can grasp the nuances and
> complexities of a problem and break it down coherently and correctly in a
> relatively short amount of time (compared to "average").
>
> A "php expert" is one that can break it down and implement a solution that
> leverages the "PHP way" of doing things and works with the language for a
> truly elegant solution.  (The "PHP way" of solving a problem is different
> than the "Java way" is different from the "C++ way".  Different languages
> have different strengths.  A language expert knows how to play to the
> strengths of the language he's using.)
>
> On Thursday 18 January 2007 9:23 am, bruce wrote:
> > hi...
> >
> > for my $0.02 worth... sometimes it's as simple as someone who can qucikly
> > grasp the issue(s) and nuances/intracacies of the issues/problems, and
> > who can then utilize php to solve the problem, as well as craft an
> > elegant solution that will scale into the future.
> >
> > peace...
> >
> >
> > -Original Message-
> > From: Jay Blanchard [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, January 18, 2007 5:56 AM
> > To: h; php-general@lists.php.net
> > Subject: RE: [PHP] What makes a PHP expert
> >
> >
> > [snip]
> > I often see job ads asking for a PHP expert and was wandering what you
> > all thought makes a PHP programmer into an expert.
> >
> > what would you mark out as the key skills that distinguishes an expert
> > from the ordinary i.e. OOP mastery, regular expressions etc.
> > [/snip]
> >
> > First I would consider number of years of programming experience
> > including how many years a programmer had been using PHP. I would
> > examine some code and look for organization, documentation, and
> > consistency. Is the programmer published (articles, books, etc) which
> > may not count against expertise?
> >
> > An expert encompasses so much more than skills. For instance, I could be
> > an expert on football because I understand history of the game, have
> > been published, understand game planning and execution, and have played
> > at the wide receiver position. Only the last 2 items really require
> > skills.
>
> --
> Larry GarfieldAIM: LOLG42
> [EMAIL PROTECTED] ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the
> possession of every one, and the receiver cannot dispossess himself of it."
>  -- Thomas Jefferson
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] multidimensional array problems

2007-01-19 Thread Larry Garfield
It's actually quite simple.  You simply add another layer of grouping.  
General case:

$result = mysql_query("SELECT a, b, c, d FROM foo ORDER BY a, b, c");
while ($record = mysql_fetch_object($result)) {
  $roster[$record->a][$record->b][] = $record;
}

ksort($roster);

foreach ($roster as $a => $bfield) {
  print $a;
  ksort($bfield);
  foreach ($bfield as $b => $record) {
print "$a: $b";
print_r($record);
  }
}

Add real output syntax to taste.


On Friday 19 January 2007 4:33 pm, nitrox . wrote:
> Ive followed your example on grouping. Im still trying to understand all of
> the code but ive made great progess on this with your example. Now I have
> one last issue and this will be solved. Ill remind here what Im trying to
> achieve
> I have a table for leagues, lookup table and team roster. There can be
> multiple game types for each game i.e. CoD2 - CTF, CoD2 - S&D, CoD2 - TDM.
> If a member is playing CoD2 CTF and CoD2 TDM there should be a table for
> each game and type showing each member playing that game/type. If a member
> is signed up for multiple games/types  he/she should have a name listed
> under each game/type.
>
> Right now my php script is only sorting by game which is putting the same
> person in for each instance of the game instead of sorting through each
> game and then type. So here is my code so far and any help is greatly
> appreciated.
>
>  include ("db.php");
>
> $memroster = "SELECT inf_league.game, inf_league.type,
> inf_member.user_name, inf_member.rank, " .
> "inf_member.country, inf_member.email " .
> "FROM inf_league " .
> "INNER JOIN inf_memberleague ON inf_league.gid =
> inf_memberleague.l_id " .
> "INNER JOIN inf_member ON inf_member.user_id =
> inf_memberleague.m_id";
> $roster = array();
> $memrosterresults = mysql_query($memroster)
> or die(mysql_error());
> while ($record = mysql_fetch_object($memrosterresults)) {
> $roster[$record->game][] = $record;
> }
> ksort($roster);
> foreach ($roster as $game => $records) {
>print "\n";
>print "{$game}\n";
>print "Name Rank Country Email\n";
>foreach ($records as $record) {
>  print "\n";
>  print "{$record->user_name}\n";
>   print "{$record->rank}\n";
>   print "{$record->country}\n";
>   print "{$record->email}\n";
>   print "\n";
> }
> print "\n";
> }
> ?>

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] most powerful php editor

2007-01-21 Thread Larry Garfield
That's interesting.  I've been trying to use Eclipse, and its code-assistance 
for PHP is some of the worst I've ever used.  I can't type "array" without it 
trying to complete that to an Array class from SPL, yet it never 
auto-completes to any function or class I wrote myself.  Nor does it seem to 
pick up on anything BUT classes.  It's terrible.  How'd you get it to behave?

On Sunday 21 January 2007 5:22 am, Peter Lauri wrote:
> I would put my vote on Eclipse. It has great support for cvs and also for
> general coding "autofilling" etc. The downside is that it is resource
> demanding...
>
> Best regards,
> Peter Lauri
>
> www.dwsasia.com - company web site
> www.lauri.se - personal web site
> www.carbonfree.org.uk - become Carbon Free
>
>
> -Original Message-
> From: Vinicius C Silva [mailto:[EMAIL PROTECTED]
> Sent: Sunday, January 21, 2007 2:54 AM
> To: php-general@lists.php.net
> Subject: [PHP] most powerful php editor
>
> hi everyone!
>
> i'd like to ask something maybe commonly asked here. what is the most
> powerful php editor?

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] most powerful php editor

2007-01-21 Thread Larry Garfield
I was originally using PHPEclipse.  When I rebuild my computer a few weeks 
ago, I decided to give the PHP-IDE package a try (given that Zend is planning 
to replace their own first-class IDE with the results of the PHP-IDE work).  
In both of them, I found the same major problems:

- Code assistance gets in my way more often than not, and has not once given 
me useful help.  (Zend Studio is a godsend here.)

- Setting up new projects out of CVS or SVN and managing them is far harder 
than it has any right to be.  (Zend Studio projects are simply based on a 
directory tree, not extra indexing, and works just fine for me.)

- The whole system is an insane memory hog.

- I've not yet figured out how to get it set up with xdebug for easy real-time 
debugging.  (That feature alone is worth using Zend Studio.)  To be fair, 
that could just be me not knowing how to do it.

I use Zend Studio at work and love it.  I keep trying to find a good open 
source development setup for home that will let me not have to spend triple 
digits on Zend Studio for home, but so far I've just not found that with 
Eclipse.

On Sunday 21 January 2007 2:01 pm, Peter Lauri wrote:
> I don't know what version you are using or what plugin you are using, there
> are more then one plugin :)
>
> To be clear: I am using Eclipse 3.1 with PHPEclipse 1.1.8 and that is
> working very well. It does auto complete classes and functions written by
> my self etc.
>
> I tried some other PHP plugin for Eclipse, and that one behavied like you
> describe, therefore my change to SourceForge PHP Eclipse Plugin.
>
> Best regards,
> Peter Lauri
>
> www.dwsasia.com - company web site
> www.lauri.se - personal web site
> www.carbonfree.org.uk - become Carbon Free
>
>
>
> -Original Message-
> From: Larry Garfield [mailto:[EMAIL PROTECTED]
> Sent: Sunday, January 21, 2007 9:31 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] most powerful php editor
>
> That's interesting.  I've been trying to use Eclipse, and its
> code-assistance
> for PHP is some of the worst I've ever used.  I can't type "array" without
> it
> trying to complete that to an Array class from SPL, yet it never
> auto-completes to any function or class I wrote myself.  Nor does it seem
> to
>
> pick up on anything BUT classes.  It's terrible.  How'd you get it to
> behave?
>
> On Sunday 21 January 2007 5:22 am, Peter Lauri wrote:
> > I would put my vote on Eclipse. It has great support for cvs and also for
> > general coding "autofilling" etc. The downside is that it is resource
> > demanding...
> >
> > Best regards,
> > Peter Lauri
> >
> > www.dwsasia.com - company web site
> > www.lauri.se - personal web site
> > www.carbonfree.org.uk - become Carbon Free
> >
> >
> > -Original Message-
> > From: Vinicius C Silva [mailto:[EMAIL PROTECTED]
> > Sent: Sunday, January 21, 2007 2:54 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] most powerful php editor
> >
> > hi everyone!
> >
> > i'd like to ask something maybe commonly asked here. what is the most
> > powerful php editor?
>
> --
> Larry GarfieldAIM: LOLG42
> [EMAIL PROTECTED] ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the
> possession
>
> of every one, and the receiver cannot dispossess himself of it."  -- Thomas
> Jefferson
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Encoding issue with £

2007-01-23 Thread Larry Garfield
On Tuesday 23 January 2007 11:55 am, Dave Goodchild wrote:
> This may be more of a mysql issue, but I am using php for my app so here
> goes...
>
> I have a fee field in the database, and when users post events they can
> specify entrance fee in £. In some, not all, of the fields I am getting,
> for example, £7 rather than £. Is this an encoding issue?
>
> Many thanks in advance...

Yep, sounds like encoding to me.  This article talks more about smart quotes 
than the £ sign, but the recommendation applies for that as well.

http://www.garfieldtech.com/blog/stupid-quotes

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] most powerful php editor

2007-01-24 Thread Larry Garfield
On Wednesday 24 January 2007 8:07 pm, Robert Cummings wrote:

> There is no way in hell one long line of SQL is easier to read than
> formatted SQL that clearly delineates the clause structure.

Sure there is.  If it's a very simple SQL statement.

I have at various times done all of the following, depending on the complexity 
of the statement in question:

SELECT id, foo, FROM foo_table WHERE id=5

(Too short to really bother with splitting up.)

SELECT id, foo, bar, baz
FROM foo_table
  INNER JOIN bar_table on a=b
  LEFT OUTER JOIN baz_table on b=c
WHERE blah
  AND stuff < narf
  OR (thingie AND other)
ORDER BY foo

SELECT a.a, a.b, a.c
b.d, b.e, b.f
  FROM a
INNER JOIN b ON whatever
ORDER BY a.b, a.c DESC

"Like any other programming language", or rather any language that isn't 
Python, formatting matters most to the reader, not to the program.  So, 
optimize your style for readability.  Readability is, of course, partially 
subjective so your style will differ from my style, but the key point is 
still to optimize the code for when you come back in 3-6 months to add a 
feature or find an obscure bug and don't remember what the frel you were 
doing.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] most powerful php editor

2007-01-24 Thread Larry Garfield
On Wednesday 24 January 2007 7:48 pm, John Meyer wrote:
> Jochem Maas wrote:
> > Curt Zirzow wrote:
> >> On 1/20/07, Vinicius C Silva <[EMAIL PROTECTED]> wrote:
> >>> hi everyone!
> >>>
> >>> i'd like to ask something maybe commonly asked here. what is the most
> >>> powerful php editor?
> >>
> >> So now we have a 4 day thread of discussing nothing but, this is what i
> >> use
> >
> > let see if we can make it a full week :-P
>
> If we want to argue about this, let's set a few guidelines as to what
> "powerful" means.  I propose these guidelines
>
> 1. Syntax highlighting

Yes.

> 2. Web server integration

Irrelevant, except insofar as it supports a real-time debugger.

> 3. Link checking
> 4. Browser check in the top three (Mozilla-IE-Opera)

These are both HTML editor features, not PHP editor features.  

For me, the big three features I want in a PHP dev environment are:

- Syntax highlighting.
- Context-sensitive code assistance.  I hate having to remember the order of 
parameters, especially when they're irregular.
- Real-time debugger.  The only one I've found that works for me so far is 
Zend's.  I cannot overstate how useful a real-time debugger is for tracking 
down bugs in complex applications.  


-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-26 Thread Larry Garfield
JOIN tableC AS C ON
> > C.fii = B.fee
> > LEFT JOIN tableD AS D ON
> > D.fuu = C.fii
> > WHERE
> > A.foo = 'someValue'
> > ORDER BY
> > afield1 ASC,
> > cfield2 ASC
> >
> >
> > While the above is contrived, most of us know such examples happen
> > quite
> > often in the wild. Not only is it easier to read, but the task of
> > adding
> > or removing selected fields is trivial.
>
> I meant ONLY the SELECT part on a single line.
>
> Only a moron would cram the FROM and all that into the same line.
>
> :-)
>
> $query = "SELECT blah1, blah2, blah3, ... blah147 ";
> $query .= " FROM table1 ";
> $query .= " LEFT OUTER JOIN table2 ";
> $query .= "ON blah7 = blah42 ";
> $query .= " WHERE blah16 ";
> $query .= "   AND blah42 ";
> $query .= " ORDER BY blah9, blah8 desc, blah6 ";
>
> is what I go for.
>
> The SELECT line is the only one that ever gets all that long, really...
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
> ___
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Larry Garfield
On Saturday 27 January 2007 7:43 am, Jochem Maas wrote:
> Larry Garfield wrote:
> > I have long since given up on raw insert/update/delete statements as the
> > syntax is all kinds nasty.  These days I just do this, which is even
> > easier and more powerful:
> >
> > http://www.garfieldtech.com/blog/simplifying-sql
>
> a quick look at those funcs gives me the impression that they are woefully
> inadequate for any level of complex realworld use.

That's interesting, because I've been using variants of that for a year now 
with much success in a dozen projects.  

> query builders are alot more fiddly to get 'right' than one might imagine,
> dealing with NULLs, booleans and dates for example (as Satyam pointed out)
> can be a right PITA.

I actually almost never use native date types in the SQL database.  I just 
store unix timestamps and do the math in PHP.  Dates are completely 
unportable anyway.  I also tend to use ints for booleans, too, although 
beefing up the switch statements in the code to handle native booleans should 
be trivial.  

> perfect automated CRUD (it's an acronym!) is kind a holy grail - and
> that is, I think, the driving force behind most attempts to crteate query
> builders.

Orthogonal persistence is, yes.  The goal here was simply to make dealing with 
arbitrary insert and update statements easier, which in practice I've found 
to be a huge success.  Full arbitrary CRUD and orthogonal persistence is much 
harder.  That's why there's a dozen ORMs out there, all of which have some 
major flaw. :-)  

> also I don't really agree with the sentiment that SQL syntax is nasty,
> personally I find it, mostly, very easy to read and powerful ... but as
> this thread shows there is no accounting for taste! :-)

What bugs me most about SQL syntax is INSERT vs. UPDATE.  I don't know the 
underlying implementation details of the engine, but from the level I work at 
(sending SQL to a database from a web app) I see no legitimate reason why 
those two very-similar statements should have ridiculously different syntax.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Larry Garfield
On Saturday 27 January 2007 1:14 pm, Jochem Maas wrote:

> >> query builders are alot more fiddly to get 'right' than one might
> >> imagine, dealing with NULLs, booleans and dates for example (as Satyam
> >> pointed out) can be a right PITA.
> >
> > I actually almost never use native date types in the SQL database.  I
> > just store unix timestamps and do the math in PHP.  Dates are completely
> > unportable anyway.  I also tend to use ints for booleans, too, although
> > beefing up the switch statements in the code to handle native booleans
> > should be trivial.
>
> mysql doesn't have booleans does it? at least not versions I have to use.
> with regard to date stuff, many people take the opposite approach and do
> most of the date math inside SQL - most DBs have kickass date calculation
> functions btw.
>
> and for the times when you need/want unix timestamps, mysql atleast, gives
> you UNIX_TIMSTAMP().

At least as of MySQL 4.1 (haven't played with MySQL 5 much yet), yes, MySQL 
has no native boolean data type that I know of.  The standard alternative is 
TINYINT(1), which technically gives you values 0-9.  

And yes, I agree that MySQL has fairly decent date manipulation routines.  But 
at work we do try for database independence when possible, so except on 
specific projects we try to avoid it.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-28 Thread Larry Garfield
On Sunday 28 January 2007 5:55 am, Jochem Maas wrote:

> > And yes, I agree that MySQL has fairly decent date manipulation routines.
> >  But at work we do try for database independence when possible, so except
> > on specific projects we try to avoid it.
>
> again we differ :-) I have never bought the 'data independence' story - in
> practice it's of little value imho most of the time (granted certain
> products do benefit - but what I build doesn't fall into that category) and
> I find it crazy to end up with a situation where the most advanced peice of
> data manipulation software in a given stack is dumbed down to the lowest
> common denominator [of DB engines]. On more complex project I try to cram
> as much of the data intregity and business logic in to the database itself
> (for which I use firebird mostly) because it means being able to create
> different clients to the data without replicating [as much] business logic
> (e.g. website and desktop app). besides which the required stored
> procedures and triggers are usually hundreds of lines less than their php
> equivalent AND more importantly they are intrinsically atomic (in the sense
> that database transaction 'should' be).
>
> rgds :-)

Well, business reasons dictate that we keep our code portable when possible at 
work.  I'm not the business person.  I just write the code. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Select record by ID

2007-01-28 Thread Larry Garfield
On Sunday 28 January 2007 5:54 pm, Francisco M. Marzoa Alonso wrote:
> On dom, 2007-01-28 at 18:51 -0500, nitrox . wrote:
> > I took the quotes off. I thought that quotes around numbers was wrong
> > also.
>
> Quotes are no necessary around numeric values, but they aren't wrong
> neither, simply optional.

Actually, I believe they are wrong in some database engines but not others.  
MySQL doesn't care.  Some others do.  Yes, it sucks. :-(

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Select record by ID

2007-01-29 Thread Larry Garfield
On Monday 29 January 2007 7:19 pm, Richard Lynch wrote:

> Looks like PostgreSQL caved in to the unwashed masses of MySQL users
> who couldn't handle not putting apostrophes around everything to me...
> [sigh]
>
> :-) :-) :-)
>
> Oh well.
>
> I personally would prefer that the DB not accept bogus input like this.
>
> Different strokes for different folks.

Different strokes indeed.  Personally I'd much rather one be able to just 
say "quote a literal, dagnabbit" and not worry about whether it was a string 
or an int.  I'm sure there's some reason for it deep in the bowels of SQL 
engines as they existed in the early '80s, but for anyone trying to not 
hand-write every frickin' SQL query and automate common tasks it makes life 
considerably more annoying.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Suggestions of GPL plugin-system?

2007-01-29 Thread Larry Garfield
I was looking for a similar good-example about 2 years ago.  What I found was 
Drupal (http://drupal.org/), and it's hook system.  I have since given up on 
writing my own plugin system and became a small fry Drupal developer. :-)

YMMV.

On Monday 29 January 2007 6:50 am, Ivo F.A.C. Fokkema wrote:
> Hi guys,
>
> I've been developing a GPL PHP/MySQL app for some time now and I would
> like to extend it with a module/plugin system. The idea would be that
> people could add a directory in a plugin path that would contain a
> bunch of PHP files extending the functionality of my application. This
> directory would then be read out, some config file parsed and whatnot,
> after which the module can be turned on by my application.
>
> Now, I could try and figure this out by myself, but that would be
> reinventing the wheel since I'm betting there is some good GPL modular
> software around (such as Joomla, PHP-Nuke, PHPbb, etc, etc.) that you have
> been working with as a coder. Could any of you suggest a certain GPL
> application that has a great module setup that I could take a look at?
>
> Thanks a lot for your time!
>
> Ivo

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Suggestions of GPL plugin-system?

2007-01-29 Thread Larry Garfield
On Monday 29 January 2007 8:37 pm, Robert Cummings wrote:
> On Mon, 2007-01-29 at 20:02 -0600, Larry Garfield wrote:
> > I was looking for a similar good-example about 2 years ago.  What I found
> > was Drupal (http://drupal.org/), and it's hook system.  I have since
> > given up on writing my own plugin system and became a small fry Drupal
> > developer. :-)
> >
> > YMMV.
>
> Be prepared to cry sometimes when you have to do 10 times the usual work
> to work around the Drupal system... that said, it's quite nice even
> though terribly inefficient with all the layers of wrapping hooks.

There is no problem in computer science that cannot be solved by adding 
another layer of indirection, except performance. :-)

When you really get into complex stuff, yes, you really have to make sure you 
think about a problem the "Drupal Way".  Of course, you could say the same 
for pretty much any complete framework.  Drupal is all about doing 
things "sideways" for maximum flexibility and extensibility, which does come 
at a penalty of conceptual complexity.

> On another up side, if you don't know how to do CSS properly, Drupal
> will hammer proper CSS usage into you as you try to style menus and
> other modules.

Also true. :-)  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] include file identifier

2007-02-03 Thread Larry Garfield
On Saturday 03 February 2007 7:27 pm, Eli wrote:
> Robert Cummings wrote:
> > Looking at the code above... it would seem you want:
> >
> > include_once()
>
> It's not the idea..
>
> I'm not trying to make that code work, I want to know which exact
> include (of the same file) does what..

Huh?

> Say you got a loop of self-include:
> e.g:
> === a.php
>  echo "\nRunning ".__FILE__." (id=X)!\t";
> if ($visited<5) {
>   echo "You are visiting here!";
>   $visited++;
>   include(__FILE__);
> }
> else {
>   echo "That's enough! Bye!";
> }
> ?>
>
> In "(id=X)!".. what's the X? You may say you can use $visited as an
> identifier, but it's not the point I mean.. I want a global include file
> identifier, that is not dependent on other variables.

realpath(__FILE__) will give you the absolute path on the server of the 
current file, which is unique.  Why you want that for what you're doing I 
have no idea, but it's the only unique identifier I can think of that isn't a 
variable or constant.  (Well, it is a constant, but you get the idea.  I 
suppose.)

The fact that you even want something like that, however, scares me.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] un include?

2007-02-10 Thread Larry Garfield
You need to rearchitect your system.

When you include a file, its code executes.  Once it has been executed, it is 
done.  It will never "rewind" itself.  You can open and edit the file, but 
the code has already executed and that execution has happened, and you cannot 
change that.  

What exactly are you trying to accomplish?  Dollars to donuts there's a much 
easier and more logical way than trying to edit an included file.

On Saturday 10 February 2007 10:18 pm, jekillen wrote:
> Hello all;
> Is there a way to un include a file once it has been included in a
> script?
> I have a situation where I need to include a php file for a variable and
> its value. Then I need to open the file and modify it in the same
> function
> 'that included the file. So far the function, as I test it does not
> appear
> to be making the intended changes to the file that has been included.
> And I am not getting any error messages.
> Am I asking too much:
> $fileToInclude = 'some_file.php';
> function edit_included_file( $fileToInclude)
> {
> include($fileToInclude);
> // use some variable in it
> $fr = fopen($fileToInclude, 'r');
> $str = fread($fr, filesize($fileToInclude))
> fclose($fr);
> // make alterations to $str
> // reopen file and write the changes
> // done but in test function I have written changes have not been made
> }
> looked through the O'Reilly book Programming Php and could not find
> a clue.
> Thanks in advance
> Jeff K

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] un include?

2007-02-11 Thread Larry Garfield
Copying back to the list where it belongs...

On Sunday 11 February 2007 11:01 am, jekillen wrote:
> On Feb 10, 2007, at 8:58 PM, Larry Garfield wrote:
> > You need to rearchitect your system.
> >
> > When you include a file, its code executes.  Once it has been
> > executed, it is
> > done.  It will never "rewind" itself.  You can open and edit the file,
> > but
> > the code has already executed and that execution has happened, and you
> > cannot
> > change that.
> >
> > What exactly are you trying to accomplish?  Dollars to donuts there's
> > a much
> > easier and more logical way than trying to edit an included file.
>
> Thanks for the reply. It is good to understand what you are telling me
> here.
> I was concerned that the file would not be accessible by a call to
> fopen when
> it has been included. It is just a series of configuration variables
> that are set
> and I want the user to be able to change one of these variables' values.
> What turned up was that I was referencing the variable by the wrong
> name in a str_replace call.
> thanks again
> JK

You're using str_replace() on PHP code to control configuration variables?  
There's a half dozen better ways that are less error prone and faster and 
more secure.

My recommendation:

- If the config is all simple values, use an ini file.  You can then use 
parse_ini_file() to read the data into an array that you can reference, and 
can write the array back out easily.  (Ini is a very simple format.)

- If you want it to be programmatically editable, put it in your database and 
be done with it.  A simple key/value table with a getter function and setter 
function is trivial to setup, but far more robust and flexible than messing 
around with the file system.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] GET doesn't work as POST

2007-02-24 Thread Larry Garfield
What I don't understand is why you're getting kind in the first place at all.  
The form you're referring to, I presume, is this one (simplified HTML to 
avoid word wrapping in email):



Regionen suchen mit ...


 
Verband: Fussballverband Region Zrich (FVRZ)  



- Alle -
Gel�cht
Eingetragen
Gltig





From that, you shouldn't be submitting a kind variable either way.  All I can 
think of is the PHP_SELF submission, which would include the same GET query 
as you used to get to that page.  I don't recall off hand if PHP_SELF 
includes the full URI or not.  

Try this: 

print_r($_GET);
print_r($_POST);
print_r($_REQUEST);

Yes, you can end up with both a GET and a POST.  (I'm not sure if it's 
technically legal in the HTTP standard, but it can happen in practice, IIRC.)  
My best guess at the moment is that "kind" is ending up in the wrong one 
somehow.


On Saturday 24 February 2007 4:51 am, Otto Wyss wrote:
> On the page
>
> http://www.orpatec.ch/turniere/5erfussball/index.php?page=bvallist.php&kind
>=regions
>
>
> I have a form with method="post" and action=" ?>". While it works fine this way, as soon as I change the form to
> method="get" it looses the parameter "kind" when I change e.g. the
> second parameter from "-Alle-" to "Gültig". Has anybody an idea why it
> works with POST but not with GET?
>
> 
> ...
>   
>
> O. Wyss

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] best framework (pear vs zend framework)

2007-03-01 Thread Larry Garfield
On Thursday 01 March 2007 3:17 am, Edward Kay wrote:

> Personally, I like Qcodo (http://www.qcodo.com) - but only because it fits
> with both my mindset and the applications I'm developing at the moment.
>
> Edward

I looked into QCodo recently when considering it for a project.  It looks like 
it would be really good for certain types of applications, specifically the 
full-blown "Web 2.0 everything-is-one-form" type apps like GMail, Basecamp, 
RoundCube, etc.  For more traditional "Web 1.5"-ish apps, it doesn't seem 
like it is flexible enough with the one-form-per-page limitation.  

That is my opinion from not actually building anything with it yet, at 
least. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Holes in mysql primary key and other db issues...

2007-03-04 Thread Larry Garfield
On Sunday 04 March 2007 1:15 pm, Mike Shanley wrote:
> Stut wrote:
> >> I have a sidebar on my site that gets a few random articles from that
> >> table, prints the titles, small blurbs, and a link. The link goes to
> >> the main article. I get the random IDs outside of mysql because I've
> >> made it more likely for newer articles to be chosen than older
> >> ones... This, accomplished via ID, because it's much easier to SELECT
> >> count(*) and slant my randomization to the last 25% of ID numbers
> >> than any other way I can think of...
> >>
> >> Of course, this means that having holes results in empty sidebar
> >> boxes... And that's not too good lookin...
> >
> > How are you selecting random entries? A common way to do this is to
> > use the MySQL rand() function, but that is exceedingly slow.
> >
> > I would suggest that you get a list of (or a subset of) the IDs in the
> > table, use PHP to randomly select however many you need and then get
> > the full data for those. You can't rely on the IDs, and the work
> > involved in resetting all the IDs such that they're sequential without
> > gaps is not worth it.
>
> I use mt_rand(0,$max_rows) to get each of my values and send the call.
> Getting an array of IDs sounds alright for now, but also sounds like it
> gets increasingly slower and the table is expanded. I'll give it a try
> though.

As Stut said, "holes" in the sequence are not a problem, they're a 
feature. :-)  They are guaranteed only to be a unique id.  You have no other 
guarantee about them, including the order in which they exist in the 
database.  It is perfectly legal in SQL to add 5 records in order to a table, 
get an auto_increment added for each, then select the whole table and get 
them in a non-numeric order unless you explicitly order them.  The ID is for 
reference purposes only, not for ordering or anything else.

What I've done in the past for selecting "three random items from the last 10" 
(which sounds close to what you're doing) is something like this:

$result = mysql_query("SELECT * FROM foo ORDER BY timefield DESC LIMIT 10");
$records = array();
while ($record = mysql_fetch_object($result)) {
  $records[] = $record;
}
array_shuffle($records);
for ($i=0; $i < 3; ++$i) {
  $use[] = $records[$i];
}

Now you have an array, $use, that is 3 random entries from the last 10, 
ordered by a time field.  The unique ID is irrelevant to that, as it should 
be.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Re: [PHP-DB] array field type

2007-03-04 Thread Larry Garfield
An array is a "multi-value field".  The standard way to do that in SQL is with 
a dependent table, something like this:

foo(fid, field_a, field_b, field_c);
foo_d(fid, value);

Or possibly: 

food_d(fid, delta, value);

where delta is essentially an array offset if you want to maintain ordering.

I don't know of a clean way to then load that data in all one query.  Each 
dependent table then becomes another simple query, and you link the data up 
in a PHP data structure of some sort.

Modifying the "array" can then get expensive as well.  If you don't have a 
delta, then a delete/insert cycle to change the values is generally the 
easiest solution.  If you do have a delta, then you may be able to 
individually identify and delete/update values in the "array" by fid and 
delta as the primary key.

On Sunday 04 March 2007 4:15 pm, Sancar Saran wrote:
> On Sunday 04 March 2007 23:04, Sancar Saran wrote:
> > Hi,
> >
> > I want to know is there any db server around there for store php arrays
> > natively.
> >
> > Regards
> >
> > Sancar
>
> Thanks for responses, it seems I have to give more info about situation.
>
> In my current project, we had tons of arrays. They are very deep and
> unpredictable nested arrays.
>
> Currently we are using serialize/unserialize and it seems it comes with own
> cpu cost. Xdebug shows some serializing cost blips. Sure it was not SO BIG
> deal (for now of course).
>
> My db expertise covers a bit mysql and mysql does not have any array type
> field (enum just so simple).
>
> I just want to know is there any way to keep array data type natively in a
> sql field.
>
> Regards.
>
> Sancar

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Is there a way to un include a file

2007-03-07 Thread Larry Garfield
No there is not, because an included file *executes* at the time it is 
included and is then done.  Any memory-resident objects (function/class 
definitions, variables, etc.) that it defies then exist until you make them 
un-exist (with unset() for variables or, well, you can't with functions and 
classes AFAIK).  

Include files are libraries.  They are not functions.  What you're looking for 
is a function.  Don't try to use include files as functions.  Therein lies 
pain.  

On Thursday 08 March 2007 12:18 am, jekillen wrote:
> Hello;
> Is there a way to un include a file once it has been included in a
> script.
> My concern is where two php files might be included in another php
> file they might have code or variables that conflict. I am thinking
> of including files with different names but follow the same pattern
> of code and variables but may have different values for variables
> or different versions of the same function.
> If there is not a specific function for un including a file (I have not
> seen any indication from my text books that there is), it seems like
> it would be nice to have one.
> Meanwhile I will be doing some experimentation.
> Thanks in advance;
> Jeff K

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Array mysteries

2007-03-11 Thread Larry Garfield
On Sunday 11 March 2007 12:02 pm, Edward Vermillion wrote:
> >> At 10:05 AM +0100 3/11/07, Tijnema ! wrote:
> >>> - You could define $wdays inside the function
> >>> function convert_from_weekday ($weekday) {
> >>> $wdays = array
> >>>(0 => "Sonntag"
> >>>,1 => "Montag"
> >>>,2 => "Dienstag"
> >>>,3 => "Mittwoch"
> >>>,4 => "Donnerstag"
> >>>,5 => "Freitag"
> >>>,6 => "Samstag"
> >>>  );
> >>>return $wdays[$weekday];
> >>>  }
> >>> $day = convert_from_weekday(0) // $day = "Sonntag"

*snip*

> > It's the technique and not the specific data thing I was
> > addressing. When I'm confronted with a case condition, I typically
> > use the switch statement. But, your solution provided me with
> > another way to look at that.
> >
> > Cheers,
> >
> > tedd
>
> But what's the cost of this in a loop, rebuilding the array each
> time, as compared to a switch statement? Just another thought...
>
> Ed

That's why you can just declare it static:

function convert_from_weekday ($weekday) {
static $wdays = array(
0 => "Sonntag",
1 => "Montag",
    2 => "Dienstag",
3 => "Mittwoch",
4 => "Donnerstag",
5 => "Freitag",
6 => "Samstag"
);
return $wdays[$weekday];
}

And then it's only ever defined once, and the lookup is just an array-key 
search that happens down in the engine.  I do this sort of mapping all the 
time.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] php 4 and 5

2007-03-11 Thread Larry Garfield
On Sunday 11 March 2007 7:14 pm, [EMAIL PROTECTED] wrote:
> Dear All,
>
> What different between 4 and 5 ?
>
> Edward.

http://us2.php.net/manual/en/faq.migration5.php
http://us2.php.net/manual/en/migration5.php

Really, I normally am not an RTFMer, but it's not like the information isn't 
already presented to you on a silver platter.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] different and logic between PHP4 and PHP5

2007-03-13 Thread Larry Garfield
On Tuesday 13 March 2007 7:50 am, Vieri wrote:

>  //$b=3;
> $c=3;
> $a=($b and $c);
> echo "A = ".$a;
> ?>
>
> in PHP4 I get:
> A = 0
> and in PHP5 I get:
> A =

> I could call this lazyness on our part or code
> portability through PHP versions or better yet, bad
> inherited coding right from the start.

A little bit of each, I think. :-)

"and", like &&, is a boolean operation.  It will return either TRUE or FALSE.  
The string representation of TRUE and FALSE is, AFAIK, not defined.  It looks 
like the effect of toString(boolean) changed from "false becomes 0" to "false 
becomes empty string".  That's quite annoying when both are logically false 
but could have side-effects like this.

OTOH, relying on a boolean data type to have a given string value in the first 
place is a bad idea to start with. :-)  Find whoever you inherited the code 
from and shoot him.  (Really, I know how badly inherited code can suck.)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] register_globals and passing variables

2007-03-14 Thread Larry Garfield
Firstly, welcome to PHP. :-)

Secondly, that's not how you would enable register_globals if they're not 
enabled.

Thirdly, you do not want to turn on register_globals.  register globals are a 
security risk.  They're disabled by default on any recent (within the past 5 
years) version of PHP, although some web hosts foolishly turn them on to be 
compatible with code written 8 years ago that shouldn't be used anymore. :-)

Instead, access the proper super-global to get the data you want.  For 
instance:

$_GET['charid']

Will have the value of the charid GET parameter passed on the URL like so:

http://example.com/index.php?charid=5

There's also $_POST['charid'], which would check just a "POST" request.  Use 
those instead of just $charid.

Also, you'll want to ensure that they're the data type you expect to avoid SQL 
injection, a security risk.  For instance, assuming you know the character ID 
will be an integer:

$charid = (int)$_GET['charid'];

Or even better:

$charid = isset($_GET['charid']) ?  (int)$_GET['charid'] : 0;

That's the "ternary operator", which is useful for setting defaults in cases 
where, for instance, no charid was passed at all.  That way you get back a 0, 
so you know you have a value and that it's an integer.

Thank you for taking PHP Security 101 in a Nutshell. :-)  Cheers.

On Tuesday 13 March 2007 10:01 pm, Jeff wrote:
> Ok, all I am new to PHP & MySQL. (please don't let this scare you off)
>
> I had my site hosted with Gisol.com and due to their very poor service and
> tech support I left them for Lunarpages.com who so far have a better
> service and their tech support is excellent!! But my pages won't pass
> variables any more.
>
> When I started I purchased two books MySQL and PHP & MySQL both published
> by O'Riely. So far the are excellent help and instructors. I wote some
> pages where I track users and their characters from an on-line game called
> World of Warcraft.
>
> On the Gisol server they were working EXCELLENT!!
>
> Once I moved to Lunarpages, the pages load ok but they don't pass the
> variables from one page to another.
>
> The below code queries the db and list's the user's in a table, and has a
> hyperlink to the right of each, on Gisol I could click the link and it
> would load the view_char.php page and it listed their character and the
> info i needed, and gave options to delete and edit. Again it was working
> beautifully.
>
>
> VIEW USERS PAGE CODE:
> $sql="SELECT f_name, l_name, char_id, char_name, char_level FROM t_char,
> t_users where t_users.user_id = t_char.user_link ORDER BY char_name ASC";
> mysql_select_db($db_select,$db);
> $result = mysql_query($sql,$db);
> echo "";
> echo"Character NameCharacter
> LevelOwner";
> while ($myrow = mysql_fetch_array($result))
> {
> echo
> "".$myrow["char_name"]."".$myrow["char_level"]."".$myrow["f
>_name"]." ".$myrow["l_name"];
> echo "View";
> }
> //$charid="[.$myrow["char_id"].]"; <- I tried this line with no
> success. Possibly have it in the wrong place??
> echo"";
>
> VIEW_CHAR PAGE CODE
> $sql = "SELECT * FROM `t_char` WHERE `t_char`.`char_id` = '$charid'"; <--
> now all this does is produce a blank page... used to work great!
> //$sql = "SELECT * FROM `t_char` WHERE `t_char`.`char_id` = '21'"; <- i
> used this code to test the page w/o the $charid string and it works FINE!!
> $result=mysql_query( $sql );
> if (!$result)
> {
> die("Could not query the database: ".mysql_error());
> }
>
> I wrote a help ticket to Lunarpages where I am now hosted and asked them to
> set the register_globals to ON thinking this was the problem based on what
> I've read and the wrote back and told me that they use suPHP to parse php
> files and I have the option of using custom php.ini files. That I could
> create a .htaccess file or put individual php.ini files in the folder that
> contains the files im running. In other words do it myself.
>
>
> So I created this file:
>
> [PHP]
>
> register_globals = on
>
> named it php.ini and dropped it in the folder with all of my files.
>
> It didn't help any.
>
> So I added this line to the first file
> include ('php.ini');
>
> all it does is add :[PHP] register_globals = on  as text at the top of my
> page now.
>
> At this point im lost!! I don't know what to do to get my A
> href=\"view_char.php?charid=".$myrow["char_id"]." to equal 

Re: [PHP] Preventing unwanted chars from outputting

2007-03-18 Thread Larry Garfield
On Sunday 18 March 2007 5:57 am, Don Don wrote:
> Hi all,
>   my program outputs some characters along with text from the database,
> these texts contain chars like ‘ ’.  How can i get rid of theses chars
> and display their meaning instead ?  I am thinking htmlspecialchars or html
> entities will do the job will it ?
>
>
>   Cheers

It sounds like you're running into character encoding issues.  They suck. :-)  
See here for details:

http://www.garfieldtech.com/blog/stupid-quotes
http://www.garfieldtech.com/blog/more-on-stupid-quotes
http://www.garfieldtech.com/blog/unicode-8-vs-16

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Preventing unwanted chars from outputting

2007-03-18 Thread Larry Garfield
On Sunday 18 March 2007 2:17 pm, Robert Cummings wrote:
> On Sun, 2007-03-18 at 13:58 -0500, Larry Garfield wrote:
> > On Sunday 18 March 2007 5:57 am, Don Don wrote:
> > > Hi all,
> > >   my program outputs some characters along with text from the database,
> > > these texts contain chars like ‘ ’.  How can i get rid of theses
> > > chars and display their meaning instead ?  I am thinking
> > > htmlspecialchars or html entities will do the job will it ?
> > >
> > >
> > >   Cheers
> >
> > It sounds like you're running into character encoding issues.  They suck.
> > :-) See here for details:
> >
> > http://www.garfieldtech.com/blog/stupid-quotes
> > http://www.garfieldtech.com/blog/more-on-stupid-quotes
> > http://www.garfieldtech.com/blog/unicode-8-vs-16
>
> I found the following to be quite informative:
>
> http://www.joelonsoftware.com/articles/Unicode.html

I do like Joel's style... :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



[PHP] PDO and buffered queries

2007-03-28 Thread Larry Garfield
HI all.  The PHP.net manual is somewhat unclear on this point, so I thought 
I'd ask here.  Does PDO automatically buffer queries the way that the mysql_* 
extension does, in order to allow multiple result sets open at the same time?  
Or is that something that has to be set on the connection, and if so, is that 
available for all drivers?

I ask because I am running into a problem with a query segfaulting on me, but 
only under PHP 5.1 with PDO from pecl.  It ran fine in PHP 5.2.0.  The only 
mention in the manual on this subject is:

http://us2.php.net/manual/en/ref.pdo-mysql.php

"If this attribute is set to TRUE on a PDOStatement, the MySQL driver will use 
the buffered versions of the MySQL API. If you're writing portable code, you 
should use PDOStatement::fetchAll() instead."

The sample code there suggests that nothing does buffered queries except the 
MySQL driver.  I find no mention of that anywhere else, though, one way or 
another.  Of course, using fetchAll(), as it suggests, means that I only get 
arrays, not objects.  (Unless I'm misreading those docs, too.)

Any PDO experts out there able to shed some light on the situation?  I'm 
thoroughly confused at this point, and the manual is quite unclear on all of 
the important details I care about. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] PDO and buffered queries

2007-03-31 Thread Larry Garfield
So there's no PDO experts out there, eh? :-(

On Wednesday 28 March 2007 11:14 pm, Larry Garfield wrote:
> HI all.  The PHP.net manual is somewhat unclear on this point, so I thought
> I'd ask here.  Does PDO automatically buffer queries the way that the
> mysql_* extension does, in order to allow multiple result sets open at the
> same time? Or is that something that has to be set on the connection, and
> if so, is that available for all drivers?
>
> I ask because I am running into a problem with a query segfaulting on me,
> but only under PHP 5.1 with PDO from pecl.  It ran fine in PHP 5.2.0.  The
> only mention in the manual on this subject is:
>
> http://us2.php.net/manual/en/ref.pdo-mysql.php
>
> "If this attribute is set to TRUE on a PDOStatement, the MySQL driver will
> use the buffered versions of the MySQL API. If you're writing portable
> code, you should use PDOStatement::fetchAll() instead."
>
> The sample code there suggests that nothing does buffered queries except
> the MySQL driver.  I find no mention of that anywhere else, though, one way
> or another.  Of course, using fetchAll(), as it suggests, means that I only
> get arrays, not objects.  (Unless I'm misreading those docs, too.)
>
> Any PDO experts out there able to shed some light on the situation?  I'm
> thoroughly confused at this point, and the manual is quite unclear on all
> of the important details I care about. :-)
>
> --
> Larry GarfieldAIM: LOLG42
> [EMAIL PROTECTED] ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the
> possession of every one, and the receiver cannot dispossess himself of it."
>  -- Thomas Jefferson

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] PDO and buffered queries

2007-04-01 Thread Larry Garfield
On Sunday 01 April 2007 3:42 am, Tijnema ! wrote:

> > On Wednesday 28 March 2007 11:14 pm, Larry Garfield wrote:
> > > HI all.  The PHP.net manual is somewhat unclear on this point, so I
> > > thought I'd ask here.  Does PDO automatically buffer queries the way
> > > that the mysql_* extension does, in order to allow multiple result sets
> > > open at the same time? Or is that something that has to be set on the
> > > connection, and if so, is that available for all drivers?
> > >
> > > I ask because I am running into a problem with a query segfaulting on
> > > me, but only under PHP 5.1 with PDO from pecl.  It ran fine in PHP
> > > 5.2.0.  The only mention in the manual on this subject is:
> > >
> > > http://us2.php.net/manual/en/ref.pdo-mysql.php
> > >
> > > "If this attribute is set to TRUE on a PDOStatement, the MySQL driver
> > > will use the buffered versions of the MySQL API. If you're writing
> > > portable code, you should use PDOStatement::fetchAll() instead."
> > >
> > > The sample code there suggests that nothing does buffered queries
> > > except the MySQL driver.  I find no mention of that anywhere else,
> > > though, one way or another.  Of course, using fetchAll(), as it
> > > suggests, means that I only get arrays, not objects.  (Unless I'm
> > > misreading those docs, too.)
> > >
> > > Any PDO experts out there able to shed some light on the situation? 
> > > I'm thoroughly confused at this point, and the manual is quite unclear
> > > on all of the important details I care about. :-)
> > >
> > > --
> > > Larry GarfieldAIM: LOLG42
> > > [EMAIL PROTECTED]ICQ: 6817012


> The manual isn't very clear at this part, but from what i understand
> of you is that you want to get objects from PDO using fetchAll().
> Normally you would used fetch()? If so, it shouldn't be too hard i
> think as fetchAll() accepts the same constants as fetch() does. You
> should pass PDO::FETCH_OBJ: as first parameter for the fetchAll()
> function.
>
> If this wasn't what you were looking for, then sorry for wasting your
> time, as I'm no PDO expert. But I thought lets give it a shot :)
>
> Tijnema

Hrm.  See, here's the trick.  I'm trying to write a PDO backend driver for an 
existing abstraction layer, as the first step in deprecating the existing 
layer.  That means I want to keep the existing flow as much as possible.  

The manual seems to say I don't get buffered queries, and therefore don't get 
the ability to run multiple queries at the same time.  However, in testing 
with MySQL I have no problem at all with multiple queries at the same time.  
I don't know if that's me misunderstanding the manual, misunderstanding how 
result sets work, or MySQL doing extra magic for me even though I don't tell 
it to.

I'm all confused. :-(

Of course, I'm also getting mysterious segfaults under PHP 5.1.6 with PDO-PECL 
that don't happen under PHP 5.2, which is another thing making it harder...

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] PDO and buffered queries

2007-04-01 Thread Larry Garfield
On Sunday 01 April 2007 3:09 pm, Jürgen Wind wrote:
> Larry Garfield wrote:
> > ...segfaults under PHP 5.1.6 ...
>
> php 5.1.5/6 was the source for many segfaults (f.e. using phpmyadmin)
> better don't use it any more. See also:
> http://bugs.php.net/bug.php?id=39036

Oh goodie.  That only includes all Ubuntu Edgy systems, of which I have 2.  
*sigh*  Anyone know of a good 3rd party repository that has 5.2? :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] Question on Portfoilo's

2007-04-09 Thread Larry Garfield
This is why one should work on an open source project.  Much easier to show 
off legally. :-)  

On Monday 09 April 2007 8:23 pm, Matt Carlson wrote:
> So i've been meaning to start a portfolio of some code, so that when I
> apply for a job, and they want code samples, I have something to show them.
>  Unfortunately, at this time, most of my work is inside of a much larger
> application, or in code that belongs to my current employer (not a php job,
> just misc. things i've made).
>
> What kind of things do you guys have in your portfolio's/code samples that
> your provide to a potential employer?  What things do you feel I should
> avoid when putting this kinda of thing together?

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] php5 oop question

2007-04-12 Thread Larry Garfield
I have never heard that described as a "fluent interface" before, but you'd 
probably like jQuery. :-)  It's a javascript library that uses much the same 
concept, although it refers to it as "function chaining".  It also operates 
on multiple objects simultaneously, which is even niftier.

On Thursday 12 April 2007 12:37 pm, Tim Stiles wrote:
> I suppose I should have summarized what I learned from that
> experiment, putting myself more squarely on topic:  Simply put, a
> Fluent interface let me move from
>
> $_input->addCheck('Integer');
> $_input->addCheck('Range',3,9);
> $_input->addCheck('NonEmpty');
>
> to
>
> $_input->addCheck('Integer')
>   ->addCheck('Range',3,9)
>   ->addCheck('NonEmpty');
>
> with almost no effort.  Not a huge timesaver, but I kept it in
> because I find the necessary code that I'll use repeatedly to be less
> cluttered and easier to read.  Less experienced developers who will
> have to work with my code felt the same way.  It just feels like less
> labor.  And as a solution, it suited this problem well, mirroring how
> most people mentally approached the issue - making it easier for them
> to understand the code at a glance.
>
> I elaborated on that problem because it was specifically the nature
> of the problem that led me to Fluent interfaces as being part of the
> solution.  I needed to set up a complex configuration within the
> object, but needed only a very simple response from it.  Like others
> pointed out, a SQL query is a very simple thing, but building one may
> involve many seemingly simple steps that occur in no prescribed
> particular order, and you don't need the result until the
> configuration is complete.  Fluent interfaces can hide complexity.
>
>
>
> 1) Fluent interfaces seem to work best when most of your methods
> alter the internal characteristics of an object. Setting properties,
> not Getting them.  You can't really use a fluent interface when you
> actually NEED a specific response from your method: they work by
> returning a reference to the object itself instead of returning a
> value - that way, the response they deliver is set up and ready to
> receive a new, unrelated method call.  You can combine the fluent
> with the conventional, but then you have to remember that any non-
> fluent call must occur last in a string of requests.  I could have
> easily written:
>
> $test = $_input->addCheck('Integer')
>   ->addCheck('Range',3,9)
>   ->addCheck('NonEmpty')
>   ->check('4.97');
> if($test)? ...
>
> but I found it more legible to stay conventional when using non-
> fluent methods.
>
> Basically, if you have configuration processes that often need to be
> called sequentially, but not always in the same sequence, Fluent
> interfaces can smooth the rough edges.
>
>
>
> 2) Fluent interfaces probably work better with thrown exceptions than
> they do with error notices.  If you generate a non-fatal error in the
> middle of a string of fluent method calls, how do you cope with it?
> Return the object anyway and let the next method continue? Not return
> the object and get a new error because your error message can't
> accept a method call?  Bail out at the point of error within your
> method instead of pointing where the error was caused?  Exceptions
> move the error handling outside of the predicted flow of the fluent
> interface, making them easier to deal with.  Your errors represent
> what actually went wrong instead of being a side-effect or symptom of
> something that went wrong earlier in the process.
>
>
> To sum up, Fluent interfaces seem to be a great solution when
> combined with a certain set of well-defined problems and practices.
> PHP5 makes them even more useful.  They save some keystrokes, they
> can improve code legibility, they can make PHP code more intuitive
> for people who weren't the ones who created it.  I don't think they
> make code execution any faster (or slower, for that matter).  It's
> worth knowing about them, but they probably shouldn't change your day
> to day practices.  As with most techniques, it becomes a matter of
> knowing when to apply this particular tool.
>
> Tim Stiles,
> WatchMaker,
> Icomex.com
> DallasPHP.org

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] isset

2007-04-15 Thread Larry Garfield
On Sunday 15 April 2007 12:07 pm, [EMAIL PROTECTED] wrote:

> > of course it's your call whether you write/run code that spits out
> > E_NOTICEs all over the place due to usage of uninitialized vars.
>
> not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to
> 'foo', right?
>
> how I understand:
> clause one: isset($_GET['var'])
> clause two: ($_GET['var'] == 'foo')
> if clause two is true, clause one MUST be true.
> if clause one is true, clause two could be true or false.
>
> means, if I look for solutions where ($_GET['var'] == 'foo') they wil
> lautomaticaly cover isset($_GET['var']) part.
> if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
> !isset($_GET['var']).
>
> or I'm missing something here?
>
> I have E_NOTICE turned off. :)

And right there is your first mistake.  The only time to not have E_NOTICE on 
is when you're using legacy code that isn't E_NOTICE compliant and you don't 
have the time to upgrade it to be compliant.  Developing without E_NOTICE 
means you're telling the computer "it's OK, let me just randomly guess where 
this bug or security hole or random typo is".  *Bad* idea.  

*Always* develop in the tightest, most restricted, most nit-picky setting you 
can get, regardless of the language.  

If you want your syntax to be a bit simpler, I frequently use helper functions 
along these lines:

function http_get_int($var, $default=0) {
  return isset($_GET[$var]) ? (int) $_GET[$var] : $default;
}

if (http_get_int('var') ==5) {
  // Do stuff
}

Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE friendly.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] CSS vs. Tables OT

2007-04-17 Thread Larry Garfield
On Tuesday 17 April 2007 3:40 pm, Robert Cummings wrote:

> > BTW, any web developer worth his or her salt with a reasonable amount of
> > practice can make CSS layouts that resize as well as table based layouts
> > everyday of the week. I will refer you to http://www.csszengarden.com/
>
> Only with hacks.

Using tables for layout *is* a hack.  A common one, but still a hack.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] CSS vs. Tables OT

2007-04-17 Thread Larry Garfield
On Tuesday 17 April 2007 8:14 pm, Robert Cummings wrote:
> On Tue, 2007-04-17 at 18:53 -0500, Larry Garfield wrote:
> > On Tuesday 17 April 2007 3:40 pm, Robert Cummings wrote:
> > > > BTW, any web developer worth his or her salt with a reasonable amount
> > > > of practice can make CSS layouts that resize as well as table based
> > > > layouts everyday of the week. I will refer you to
> > > > http://www.csszengarden.com/
> > >
> > > Only with hacks.
> >
> > Using tables for layout *is* a hack.  A common one, but still a hack.
>
> No, it's old school, the only way to do complex layout in the past. At
> least tables are backward and forward compatible. CSS is only
> semi-forward compatible.

Using a semantic data structure for tabular data as a layout language?  That's 
a hack.  It was a hack that was the only way to accomplish many things in 
1997, but that doesn't make it any less of a hack.

No, CSS is not perfect.  Far from it.  Of course, designers who still, in 
2007, think they're working in a print medium are equally far from perfect.  

They could all use improvement, but let's not pretend that using a chisel as a 
screwdriver isn't a hack just because it happens to have a flat end.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] CSS vs. Tables OT

2007-04-17 Thread Larry Garfield
On Tuesday 17 April 2007 9:54 pm, Robert Cummings wrote:
> On Tue, 2007-04-17 at 21:21 -0500, Larry Garfield wrote:
> > On Tuesday 17 April 2007 8:14 pm, Robert Cummings wrote:
> > > On Tue, 2007-04-17 at 18:53 -0500, Larry Garfield wrote:
> > > > On Tuesday 17 April 2007 3:40 pm, Robert Cummings wrote:
> > > > > > BTW, any web developer worth his or her salt with a reasonable
> > > > > > amount of practice can make CSS layouts that resize as well as
> > > > > > table based layouts everyday of the week. I will refer you to
> > > > > > http://www.csszengarden.com/
> > > > >
> > > > > Only with hacks.
> > > >
> > > > Using tables for layout *is* a hack.  A common one, but still a hack.
> > >
> > > No, it's old school, the only way to do complex layout in the past. At
> > > least tables are backward and forward compatible. CSS is only
> > > semi-forward compatible.
> >
> > Using a semantic data structure for tabular data as a layout language? 
> > That's a hack.  It was a hack that was the only way to accomplish many
> > things in 1997, but that doesn't make it any less of a hack.
> >
> > No, CSS is not perfect.  Far from it.  Of course, designers who still, in
> > 2007, think they're working in a print medium are equally far from
> > perfect.
> >
> > They could all use improvement, but let's not pretend that using a chisel
> > as a screwdriver isn't a hack just because it happens to have a flat end.
>
> You say "Using tables for layout *is* a hack". Unfortunately for you
> tables were intended for laying out tabular data. Thank you, thank you
> very much.

Tabular data != 4 column page layout.

Tabular data = records and fields.  Come on, you've used SQL.  That's a table.  
Sidebars are not tables.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] php exception handling

2009-10-11 Thread Larry Garfield
On Sunday 11 October 2009 6:09:46 pm Tommy Pham wrote:

> Lars,
>
> Here's a pseudo code:
>
> try {
>   if (!$valid) {
> throw new Exception("Test failed.");
>   } else {
>// do something
>   }
> } catch (Exception $e) {
>   // set/print a user friendly message to send to output
>
>   // set a detailed message using debug_backtrace() or any other
> information relevant for easier troubleshooting // log and/or email
> detailed message
> }
>
> Regards,
> Tommy

Actually the else clause is not necessary.  That's one of the nice things 
about exceptions.  If you throw an exception, processing jumps to the 
appropriate catch and never returns.  

try {
  // Do normal stuff.

  if (!$valid) {
throw new Exception('OMG!');
  }

  // Do more normal stuff.
}
catch (Exception $e) {
  // Print user friendly message.
  // Log detailed information or whatever you're going to do.
}


-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Classes and Functions

2009-11-01 Thread Larry Garfield
On Sunday 01 November 2009 2:50:55 pm Daniel Kolbo wrote:
> Hello,
>
> Is there a way to see what objects and functions a script
> loaded/required/used?
>
> I could recursively loop through the globals, but if objects were unset,
> then i may miss some.
>
> I could make a 'tracking' object and every time i load/include a file
> (which contains a class def or a function def) to add that file to the
> tracking object...but it would be nice if i didn't have to modify my
> existing code to see which objects and functions a script actually used,
> or at least, requested and loaded into memory.
>
> Thanks in advance,
> Daniel Kolbo
> `

Depends what you are trying to do with it, but I suspect these are a good 
start:

http://www.php.net/get_defined_functions
http://www.php.net/get_defined_vars
http://www.php.net/get_defined_constants
http://www.php.net/get_declared_classes
http://www.php.net/get_declared_interfaces
http://www.php.net/get_included_files

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Good SQL builder class

2009-12-05 Thread Larry Garfield
I actually spent a great deal of time trying to make purely array based query 
builders, and came to the conclusion that it's not possible to make a really 
robust one.  However, you can do it with OO and arrays.

Have a look at Drupal 7 (current development version of the Drupal CMS).  It 
includes a new DB layer totally rewritten to use PDO and includes a series of 
robust SQL builders.  It's also really easy to separate from Drupal; you need 
to comment out 2, perhaps 3 lines of code total.  At some point I want to spin 
it off as a stand-alone project, but for now it's easy to rip out.  In fact 
it's already been ripped out and backported to Drupal 6, so you can grab the 
code from there (GPL) and tweak as needed.

http://drupal.org/project/dbtng

On Friday 04 December 2009 7:09:55 am Anton Heuschen wrote:
> Good day.
>
> I'm looking for a good class to handle building dynamically from and
> array (and if it is good it will automatically determine / or even
> have different methods) to handle mutli-dimensional arrays or simple
> associative arrays ... and build the SQL statement :
>
> for example I have an array :
>
> $home[$suburb]["street"] = test1;
> $home[$suburb]["housenr"] =2;
>
>
> Ok to keep it simple to 2, then I want to build the SQL like
>
> insert into homes (STREET, HOUSENR) VALUES ($val1,$val2);
>
>
> something like that, but I could also pass some array like :
>
> $home["street"] = test2;
> $home["housenr"] = 2;
>
>
> but the idea stays the same = the index is the name of the DB fields
> and the assigned value the element
>
>
>
> I have looked on hotscripts and phpclasses but I have no idea how good
> the solutions are that I have found thus far - therefor need some
> recommendation from someone else past experience of this

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] OOP Design Question

2009-12-20 Thread Larry Garfield
On Sunday 20 December 2009 10:35:56 am Daniel Kolbo wrote:
> Hello PHPers,
>
> I have a collection of about 60 objects (class definitions).  They are
> all very similar.  They all share a substantial % of the same core.  But
> they all have slight variations as well.  The approach I took was to
> make an abstract core class, and each of the 60 objects extends that
> core.  This works, but...
>
> Here's my problem, not every php/http request requires all 60 objects.
> At this point, I do not know in advance which objects will be required,
> so i include the class def of all 60 objects every time...  I don't like
> this idea as it seems a 'bloated' approach.
>
> So now i'm thinking instead i'll just have one object which has the
> union of all the 60 objects' methods.  But i'm not too happy with this
> either b/c (i) now each instantiated object is carrying around a lot of
> unneccessary baggage, (ii) i lose modularity of code, and (iii) the code
> does not make as much 'intuitive' sense.  For (iii), 'why does this
> object have this method?' type questions another programmer would ask
> (or me a year from now).  The answer would be 'efficiency concerns',
> which i'm aware that you generally don't want to compromise code
> readability for efficiency if avoidable.
>
> Maybe this would be the perfect opportunity for the php autoload
> functions...?
>
> Thanks for your help/thoughts/comments,
> dK
> `

Yep, this is a textbook case for a proper autoload setup.  And no, cramming 
all of the functionality into one mega class won't get you any efficiency.  In 
fact, it would be just as wasteful as loading all 60 classes even when you're 
only going to use 2; you're still loading up roughly the same amount of code.  
Parsing it as one mega class or one big parent with a few small child classes 
is about a break-even as far as performance goes, but the mega class is much 
poorer architecture.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] efficiency of include()

2009-12-20 Thread Larry Garfield
On Sunday 20 December 2009 10:45:45 am Daniel Kolbo wrote:
> Hello PHPers,
>
> This is a two part question:
>
> 1) Is it faster to include one file with lots of code, or many separate
> smaller individual files?  Assume the one massive file is merely the
> concatenation of all the smaller individual files.  (I am assuming the
> one massive file would be faster..., but i wanted to get confirmation).

Conventional wisdom is that the one big file is faster, since it requires one 
disk I/O hit instead of several.  HOWEVER, if you're only using a small 
portion of that code then it could be faster to load only the code you really 
need.  Where the trade off is varies with your architecture, the amount of 
code, ad how good the disk caching of your OS is.

> 2) Suppose php has to invoke the include function 100 times.  Suppose
> all files are on average the same size and contain the same number of
> instructions.  Would it be faster to include the same exact file 100
> times as opposed to 100 different file names?  Basically, does the
> engine/parser take any shortcuts if it notices that the file name has
> already been included once?

I'm pretty sure that PHP will recognize that it's already parsed that file and 
keep the opcode caches in memory, so it needn't hit disk again.  I've not 
checked into that part of the engine, though, so I may be wrong there.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] OOP Design Question

2009-12-20 Thread Larry Garfield
On Sunday 20 December 2009 1:08:46 pm you wrote:

> >> Maybe this would be the perfect opportunity for the php autoload
> >> functions...?
> >>
> >> Thanks for your help/thoughts/comments,
> >> dK
> >> `
> >
> > Yep, this is a textbook case for a proper autoload setup.  And no,
> > cramming all of the functionality into one mega class won't get you any
> > efficiency.  In fact, it would be just as wasteful as loading all 60
> > classes even when you're only going to use 2; you're still loading up
> > roughly the same amount of code. Parsing it as one mega class or one big
> > parent with a few small child classes is about a break-even as far as
> > performance goes, but the mega class is much poorer architecture.
>
> Thanks for your insight.
>
> I could probably setup autoloading, but I wonder if I would do it
> 'properly'.  Do you have a link or reference that you'd recommend for
> howto do a 'proper autoload setup'?
>
> Thanks,
> dK

Well, there is no universal agreement on what a "proper" setup is. :-)  There 
is a group trying to establish a Java-like standard for all projects to use 
once they get to PHP 5.3 and namespaces, but there are still issues to work 
out and IMO it's not actually a good approach for many use cases.  I'd argue 
that "proper" depends in a large part on your specific use case.

The most important aspect of a good autoload mechanism, though, is that it's 
fast and extensible.  Use spl_autoload_register() instead of __autoload(), and 
make sure that you keep the runtime of your autoload callbacks to an absolute 
minimum.  (A DB hit per autoload, for instance, is a no-no.)

Beyond that, varies with your project.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Multiple Inheritance Concern

2009-12-25 Thread Larry Garfield
On Friday 25 December 2009 8:02:06 pm Daniel Kolbo wrote:
> Hello PHPers,
>
> I've learned that php doesn't support multiple inheritance, b/c if you
> need multiple inheritance usually it is a sign you've got a design
> imperfection...or so they say.
>
> Well, I'm using a framework (Codeigniter), and i'm extending the core
> libraries.  The trouble is, I want to also extend a second custom class,
> and I don't want to change the core codeigniter class definitions as
> this makes for awkward upgrades.
>
> I read about mixins - no thank you.  i do not want to even think about
> mixins as it looks like it would be the source of all debug hell...
>
> What's a programmer to do?  Is the only option i am really left with to
> duplicate the code in each class?
>
> Thanks,
> dK
> `

If the original author of one or both libraries did their job right, they'll 
have provided an interface as well as the class that implements it.  Then you 
can implement the interface and pass through to a new instance using 
composition.

To wit:

interface AInterface {
  public function doA();
}

interface BInterface {
  public function doB();
}

class A implements AInterface {
  public function doA() { ... }
}

class B implements BInterface {
  public function doB() { ... }
}

class YourClass extends A implements BInterface {

  protected $b;

  public function __construct() {
$this->b = new B();
  }

  public function doB() {
return $this->b->doB();
  }
}

(It would probably be a little more complicated in a real use case, but 
hopefully that should get you the idea.)

Mind you, that presumes that the code you're dealing with provides interfaces 
and when doing type checking checks against the interfaces rather than the 
classes themselves.  If they don't, you should file a bug against that base 
library as They're Doing It Wrong(tm).

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Accessing Objects - Object to Object Communication

2009-12-26 Thread Larry Garfield
On Saturday 26 December 2009 3:38:44 pm Allen McCabe wrote:

> Here are some code snippets:
>
> Content.class.php:
> class Page {
>
> private $db;// Contains reference to instance of the
> Database class
> private $notify;// Contains reference to instance of the
> Notifier class
> private $URL;
>
> public function __construct($dbconnection, $root, $id = null)
> {
> $this->db = $dbconnection;
> $this->notify = Notifier::getInstance();
> $this->URL = $root . 'content/';
>
> if (isset($id)) {
> $result = $this->db->query('SELECT * FROM `content` WHERE
> `page_id` = \''. $id .'\'');
> $data = $this->db->fetch_array($result);
> }
> }
> }
>
> header.php:
> require_once('lib/class/Database.class.php');
> $db = new Database($dbhost, $dbuser, $dbpass, $dbname);
> $db->connect();
> require_once('lib/class/Notifier.class.php');
> $notify = Notifier::getInstance(); // self instantiates
> require_once('lib/class/Content.class.php');
> $page = new Page($db, ROOT);
>
>
> Does this look right? I don't think I've ever seen two -> operators
> together like this before...
>
> I don't want to keep connecting to the database, and more importantly, my
> Notifier class should only be a single instance, so I need to be able to
> amend to a static array variable in that class from within other classes.
>
> Thanks for any help you can provide, and happy holidays!

Chaining multiple -> operators together like that is totally fine, and what 
you're doing here with the database is a good example of simple dependency 
injection.  In fact, you should do the same with the notifier class and pass it 
into the constructor of Page as well rather than making it a syntactic 
singleton.

For extra credit, wrap all of that into a factory function or factory object:

function create_page($root) {
  $db = create_your_db();
  $notifier = create_your_notifier();
  return new Page($db, $notifier, $root);
}
$new_page = create_page($my_root);

And the db and notifier routines can be as simple or complex as needed for your 
use case.  They could be singletons themselves, but don't have to be.  And in 
either case, Page() now doesn't know or care so you can change your mind 
without affecting Page.  Page is now loosely coupled, and all is right with the 
world.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Multiple Inheritance Needed in OOP?

2009-12-28 Thread Larry Garfield
On Monday 28 December 2009 9:45:03 pm Daniel Kolbo wrote:
> Hello,
>
> Okay so PHP designers explicitly decided against multiple inheritances,
> but aren't there legitimate needs for multiple inheritance in OOP?
>
> For example, consider the following three classes (A,B,C) with the
> following properties (a number is a distinct property or method).
>
> A: 1, 2, 3
> B: 1,3
> C: 1, 2,
>
> I would like to set the 3 classes up so that no object has 'extra'
> properties than it requires, so that no property has to be
> declared/defined in two or more classes, and so that we are strictly
> using single inhertiance.  I don't think it's possible.  I've been
> incorrect beforee...If i'm incorrect please let me know how to set this
> up as a single inhertance class structure.
>
> If this is not possible, why doesn't the PHP community implement
> multiple inheritance?  (I'm anticipating that someone will say, you
> simply need to redefine what you are calling your objects so that the
> properties do permit a single inheritance...)
>
> I'm very interested to hear why there is the dogma of single inheritance
> only.
>
> Thanks,
> dK
> `

Because pure multiple inheritance can lead to all sorts of highly weird 
behavior when you don't know which parent class you mean at any given time.  
Single inheritance is just easier to wrap your head around, and wrap the 
compiler's head around.

What you're looking for is composition, which can do pretty much what you're 
looking for.  See my last reply to you on this list from Christmas day.

There's been some discussion of implementing "traits" in later versions of 
PHP, but no concrete patches so far.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] If design patterns are not supposed to produce reusable code then why use them?

2009-12-31 Thread Larry Garfield
Meant to send this to the list, sorry.

--  Forwarded Message  --

Subject: Re: [PHP] If design patterns are not supposed to produce reusable 
code then why use them?
Date: Thursday 31 December 2009
From: Larry Garfield 
To: "Tony Marston" 

On Wednesday 30 December 2009 10:50:40 am Tony Marston wrote:
> I have recently been engaged in an argument via email with someone who
> criticises my low opinion of design patterns (refer to
> http://www.tonymarston.net/php-mysql/design-patterns.html ). He says that
> design patterns are merely a convention and not a reusable component. My
> argument is that something called a pattern is supposed to have a recurring
> theme, some element of reusability, so that all subsequent implementations
> of a pattern should require less effort than the first implementation. If
> design patterns do not provide any reusable code then what is the point of
> using them?
> 
> 
> 
> I do not use design patterns as I consider them to be the wrong level of
> abstraction. I am in the business of designing and developing entire
> applications which comprise of numerous application transactions, so I much
> prefer to use transaction patterns (refer to
> http://www.tonymarston.net/php-mysql/design-patterns-are-dead.html and
> http://www.tonymarston.net/php-mysql/transaction-patterns.html ) as these
> provide large amounts of reusable code and are therefore a significant aid
> to programmer productivity.
> 
> 
> 
> What is your opinion? Are design patterns supposed to provide reusable code
> or not? If not, and each implementation of a pattern takes just as much
>  time as the first, then where are the productivity gains from using design
>  patterns?

It depends what you're reusing.  Design patterns are reusable concepts, not 
reusable code.  That's the key difference.

Knowledge of design patterns is like knowledge of how different food 
ingredients interact.  "Hm, this needs something to bring out the taste more, 
so I'll add salt."  You're not going to add the same salt to each dish, 
obviously, but the idea is that you need something that will bring out the 
taste, and there are certain spices that will bring out the existing taste of 
whatever it is you put them on, such as salt.  

Similarly, if you want, say, a piece of code that will connect to a database, 
you want a pre-built library, not a design pattern.  (There's no shortage of 
those.)  If, however, you want a mechanism by which you can have different 
implementations of the same system, and want to swap them out without 
rewriting the calling code, then what you want is the factory *pattern*.  
There may not be existing code yet for whatever system you're writing.  
However, once you recognize "Ah, I want a common interface with a swappable 
implementation, and I want to pick the implementation at runtime based on some 
arbitrarily complex logic", then you know you don't need to think through how 
you go about structuring the code to do that.  Instead, you look up a 
description of the factory pattern and go "ah, that makes sense, and it solves 
3 problems that I didn't realize I'd run into later".  Then you go and 
implement code that follows that pattern, and you don't have to think through 
the algorithm.

Now, it is possible to make generic implementations of some patterns that you 
can re-leverage.  Eg, you can have a common factory interface and a way to 
request a factory, which in turn will give you the implementation object you 
want.  The common elements of those factories you move up to a parent class, 
and therefore reuse code that way.  This is known as a "Factory factory", and 
is in some cases very useful and in others gross over-engineering.  Knowing 
which is which is something you learn through experience.

--Larry Garfield

---

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



Re: [PHP] If design patterns are not supposed to produce reusable code then why use them?

2010-01-01 Thread Larry Garfield
e.

Yes, always blindly following a given design pattern for the sake of following 
a design pattern is stupid.  Blindly ignoring established "solved problems" 
just for the sake of avoiding those pointless design patterns is just as 
stupid.

Remember, code is irrelevant.  You don't sell code.  You sell ideas and 
concepts, implemented in code.  By not having to re-invent the ideas and 
concepts every time, you can save a great deal of time and effort, and 
potentially a great deal of code that you don't need to rewrite later from 
going down a dead-end.

There's two kinds of developers: Those that understand how they're using 
design patterns and those that don't understand design patterns. :-)  But both 
are, in practice, using them, even if some are doing so badly (either over- or 
under-using them).

--Larry Garfield

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



Re: [PHP] Open Source CMS

2010-01-21 Thread Larry Garfield
On Wednesday 20 January 2010 10:29:38 pm Hendry wrote:
> Hi,
> 
> Thanks for both Robert and Allen for sharing, I agree, Drupal is very
> easy to start with, and it is also very powerful, but somehow, I find
> it very hard to extend which is might be due to my lack of experience.
> 
> # Hendry

The way you extend Drupal is rather different than most other systems due to 
its architecture.  However, once you wrap your head around doing so it is 
extremely extensible.  The online docs on drupal.org are a pretty good place 
to start, but I can also recommend this book:

http://www.packtpub.com/drupal-6-module-development/book

Disclaimer: The author used to work with me, and I'm a Drupal core developer 
so I am admittedly biased. :-)

--Larry Garfield

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



Re: [PHP] SQL insert () values (),(),(); how to get auto_increments properly?

2010-02-14 Thread Larry Garfield
On Sunday 14 February 2010 03:15:16 am Rene Veerman wrote:
> On Sat, Feb 13, 2010 at 3:46 PM, Joseph Thayne  
wrote:
> > In order to make this as "sql server independent" as possible, the first
> > thing you need to do is not use extended inserts as that is a MySQL
> > capability.  If you are insistent on using the extended inserts, then
> > look at the mysql_info() function.  That will return the number of rows
> > inserted, etc. on the last query.
> 
> But as previous posters had pointed out (thanks) i can't see which rows
>  failed. As i'm dealing with 3rd-party data, that's an issue.
> 
> I also didn't know it was mysql-specific, that multi-insert..
> 
> And i tried looking up the sql-standard docs, only to find that they
> cost over 200 euro per
> part (14 parts).
> I've sent angry emails to ansi.org and iso.org (commercial lamers
> operating under .org, yuck), about how cool a business model that
> charges a percentage of profits per implementation would be, instead
> of charging high prices up-front for a potentially bad/complicated
> piece of spec.
> 
> But back to the problem at hand; it looks like i'll have to forget
> about using 100s of threads for my newsscraper at the same time, and
> settle for a few dozen instead.
> Then i can just do single inserts (per hit) and retrieve the
>  last_insert_id().
> 
> One question remains: it is probably not (concurrently-)safe to do a
> sql-insert from php and then a last_insert_id() also from php..?
> I still have to build a stored procedure to do-the-inserting and
> return the last_insert_id()?

That's perfectly safe to do as long as it's within the same PHP request. 
(Well, the same DB connection, really, which is 99% of the time the same 
thing.)  last_insert_id() is connection-specific.

I believe (it's been a while since I checked) the MySQL documentation says 
that last_insert_id() with a multi-insert statement is not reliable and you 
shouldn't rely on it having a worthwhile meaning anyway.  Or at least it said 
something that made me conclude that it's safest to assume it's unreliable for 
a multi-insert statement.

If you're concerned about performance of that many bulk writes, there's 3 
things you can do to help:

1) Use InnoDB.  It uses row-level locking so lots of writes doesn't lock your 
whole table as in MyISAM tables.

2) Disable indexes on the table in question before running your bulk insert, 
then re-enable them.  That's considerably faster than rebuilding the index 
after each and every insert as they only need to be rebuilt once.

3) If you're on InnoDB, using transactions can sometimes give you a 
performance boost because the writes hit disk all at once when you commit.  
There may be other side effects and trade offs here, though, so take with a 
grain of salt.

--Larry Garfield

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



Re: [PHP] array conversion

2010-02-18 Thread Larry Garfield
On Thursday 18 February 2010 11:58:28 pm Paul M Foster wrote:
> On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote:
> > Hi guys. How to convert an array like:
> >
> > Array
> > (
> > [0] => key1
> > [1] => value1
> > [2] => key2
> > [3] => value2
> > )
> >
> > to
> >
> >
> > Array
> > (
> > [key1] => value1
> > [key2] => value2
> > )
> >
> > Is there a built-in function to do this?
> > Please Cc me. :)
> > Thank you in advance.
> 
> I don't believe so, but rolling your own should not be too hard:
> 
> $a = array($key1, $value1, $key2, $value2);
> $b = array();
> $numitems = count($a);
> 
> for ($i = 0; $i < $numitems; $i++) {
>   if ($i % 2 == 0) {
>   $saved_key = $a[$i];
>   }
>   elseif ($i % 2 == 1) {
>   $b[$saved_key] = $a[$i];
>   }
> }
> 
> Code is crude and untested, but you get the idea.
> 
> Paul

This would be even shorter, I think:

foreach ($items as $i => $value) {
  $temp[$i % 2][] = $value;
}
$done = array_combine($temp[0], $temp[1]);

(Also untested, just off the cuff...)

--Larry Garfield

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



[PHP] Memory investigation

2010-03-02 Thread Larry Garfield
Hi folks.  I have a complicated PHP app that is eating up more memory than I 
think it should.  I have a couple of theories as to where it could be going, 
but I need some way to verify it.

There are a number of large data structures (mostly arrays) that get built up 
throughout the course of the request.  What I'd like to be able to do is at 
certain points check to see how much memory those data structures are using.  
Because they're not all built at once, the usual "check memory before, build, 
check after" routine won't work.  Plus, that gets screwed up by PHP's use of 
copy-on-write at times.

I know that it would result in essentially over-reporting, but I would ideally 
like to be able to ignore the copy-on-write issue and say "if this variable 
were the only thing in memory (and its dependents, of course, for a nested 
array), what would its memory usage be?  I just have no idea how to do that.

Anyone have a suggestion for how to accomplish that?

--Larry Garfield

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



[PHP] Code samples in OOo Presenter

2010-03-21 Thread Larry Garfield
Hi all.  

I have a busy conference season coming up, and will be giving a number of 
presentations that involve code, specifically PHP.  I am going to want to put 
code onto slides in OpenOffice (3.1 specifically, using Kubuntu 9.10), but to 
date I've never figured out a good way to do that.  Anyone know of a good way 
to do syntax-highlighted code in OOo?

Things I've tried in the past:

1) Just throw code onto the slide, no highlighting.  This works, but is ugly 
and harder to read or demonstrate what I am doing.  It's my usual fallback.

2) Screen-shot from a web page that uses syntax highlighting, such as PHP's 
built-in highlighting.  Very difficult to prepare since the sizing is usually 
all off.  Ugly.  Very difficult to edit and change because the screen caps have 
to be regenerated.  And PHP's default coloring for highlighting frequently 
clashes with the slides and looks godawful on a projector.  (I once ended up 
with blue text on a black slide.  That was a major fail.)

3) Jump out of the slides into an IDE.  Works, but totally breaks the flow of 
the presentation.  The IDE usually also has text that's way too small, and I 
have to reconfigure it into a "presentation mode", often on the fly. It also 
makes discrete snippets harder to show, since there's still the entire rest of 
the IDE there.

I don't like any of these options. :-)  I don't know what the alternative is, 
though.  Ideally I'd love to have a custom text region or format or something 
that is "take this and highlight it properly", but I don't know if such a 
plugin exists.

I could be talked into using KPresenter / KOffice instead if that would be 
easier, but as I am on Linux I have no access to KeyNote or PowerPoint.

Any suggestions?

--Larry Garfield

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



Re: [PHP] Code samples in OOo Presenter

2010-03-21 Thread Larry Garfield
On Sunday 21 March 2010 05:41:55 pm Ashley Sheridan wrote:

> > I don't like any of these options. :-)  I don't know what the alternative
> > is, though.  Ideally I'd love to have a custom text region or format or
> > something that is "take this and highlight it properly", but I don't know
> > if such a plugin exists.
> >
> > I could be talked into using KPresenter / KOffice instead if that would
> > be easier, but as I am on Linux I have no access to KeyNote or
> > PowerPoint.
> >
> > Any suggestions?
> >
> > --Larry Garfield
> 
> Could you use highlight_string() on the code example in a web page then
> copy that from the browser and paste that into your presentation? It
> should then preserve the formatting used on the browser display, and let
> you easily modify the font size.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

I will have to see if OOo preserves formatting when I do that.  However, that 
still leaves the problem of highlight_string()'s colors being rather poor for 
on-screen.  Are those easily configurable?  That would at least give me a 
decent result, kinda, even if it's not as clean as doing it all within the 
presentation program.

--Larry Garfield

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



Re: [PHP] Will PHP ever "grow up" and have threading?

2010-03-22 Thread Larry Garfield
Perhaps if you asked a question you'd get an answer rather than coming off as 
an angry immature crybaby in your last paragraph...  No, I'm not going to 
dignify your post with a real answer.  Come back when you can ask a real 
question and maybe you'll get a real answer.

--Larry Garfield

On Monday 22 March 2010 07:02:30 pm Daevid Vincent wrote:
> I've been using PHP for a decade or so (since PHP/FI) and love it. The one
> problem that seems to always keep coming back on enterprise level projects
> is the lack of threading. This always means we have to write some back-end
> code in Ruby or Java or C/C++ and some hacky database layer or DBUS or
> something to communicate with PHP.
> 
> Will PHP ever have proper threading? It would sure let the language take
> the next logical leap to writing applications and daemons. I love the idea
> that Rails/Ruby have where you can just load objects in memory once and
> keep using them from page to page (this is NOT the same as a $_SESSION,
> it's way more flexible and powerful).
> 
> But more importantly, in one application I'm working on, we need to connect
> to an Asterisk system for the IVR abilities. This means we have Ruby doing
> all that fun stuff and PHP doing the web stuff, but we're also duplicating
> a LOT of work. Both Ruby AND PHP now have to have ORMs for the user who's
> calling in, advertisements served, products shown, etc. We could have used
> Rails for the web portion, but I want to stay with PHP and I'm sure I don't
> have to explain to you PHPers why that is. Without threads, PHP just isn't
> even an option or only one user would be able to call in at a time.
> 
> The pcntl stuff is not feasible. It's a hack at best. Spawning multiple
> scripts is also a recipie for disaster.
> 
> When will the PHP core-devs (Zend?) realize that PHP is much more than a
> hook to a database. It's much more than web pages.
> 
> Is this a case of "it's too hard"? Or is it a case of PHP core developers
> just being douche-bags like they are about the whole
> "foo($set_this_parameter=$bar);" bull$hit??! (there is NO reason NOT to let
> the developer choose WHICH of the list of parameters they want to set in a
> function/method call aside from being stubborn! Especially when there are
> many parameters and you can't overload functions like you can in Java or
> other typed languages)
> 
> As usual, I created a poll here too:
> http://www.rapidpoll.net/awp1ocy
> 
> Past polls are below:
> http://www.rapidpoll.net/8opnt1e
> http://www.rapidpoll.net/arc1opy (although someone hacked this poll and
> loaded up the 76 votes like a little cheater)
> 

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



Re: [PHP] Will PHP ever "grow up" and have threading?

2010-03-22 Thread Larry Garfield
On Monday 22 March 2010 10:51:14 pm Tommy Pham wrote:
> Threading is one of the 2 two main reasons why I moved to Java &
> asp.net (C#).  I've built a PHP based web crawler about 10 years ago.
> I ran into some problems: cookies, form handling and submission,
> threading, and application variables.  I later found some solutions
> for cookies, form handling & submission.  But no solution for
> threading and application variables.  Thus the move.  Here's a simple
> example of one of the many uses for threading.  For an e-commerce
> site,  when the shopper requests for a category (ID), you can have a
> thread to get all subcategories for that category, another thread to
> get any assigned products,  another thread to fetch all manufacturers
> listed under that category, another thread to fetch any filters (price
> ranges, features, specs, etc) set by the store owner that would fall
> under that category, etc...  versus what PHP currently doing now:
> fetch subcategories, then fetch assigned products, then fetch
> manufacturers, etc  Performance would increase ten fold because of
> parallel (threading) operations versus serial operations.  Add that to
> application variable (less memory usage and CPU cycles due to
> creating/GC of variables that could be used for an entire application
> regardless of requests & sessions), you have an excellent tool.
> 
> Regards,
> Tommy

Threading is also much more difficult to program for safely, because thread 
order is non-deterministic.  Do you really want to unleash hoards of 
marginally competent programmers on a threaded enviornment? :-)

Also, the architecture you describe above is fine if you're scaling a single 
server really big.  PHP is designed to scale the other direction: Just add 
more servers.  There's no data shared from one request to another, so there's 
no need to share data between web heads.  Throw a load balancer in front of it 
and spin up as many web servers as you need.  

The "shared nothing" design is very deliberate.  It has design trade-offs like 
anything else.

PHP is a web-centric language.  It's not really intended for building tier-1 
daemon processes, just like you'd be an idiot to try and code your entire web 
app in C from the start.

--Larry Garfield

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



Re: [PHP] Will PHP ever "grow up" and have threading?

2010-03-23 Thread Larry Garfield
On Tuesday 23 March 2010 11:32:10 pm Tommy Pham wrote:
> On Tue, Mar 23, 2010 at 9:06 PM, Teus Benschop  
wrote:
> > When looking at PHP as used in enterprise class applications, we can see
> > the following happening. Let imagine that we have a site that gets a
> > 1000 requests per second. That seems to be a good candidate for
> > threading so as to be able to handle the 1000 requests per second. The
> > site runs PHP and Apache. Well, what happens? Each request coming in is
> > handed of to a separate instance of Apache. Thus the site would be able
> > to process many requests simultaneously. It looks as if parallel
> > computing is taking place here, which looks much like threading. Even
> > though PHP itself does not know about threads, and does not need to, I
> > think, the whole process of handling the 1000 requests per second uses
> > parallel computing. There are no performance bottle-necks here. Teus.
> 
> # of requests / second can be solved by load balancers/clusters.  What
> about the multiple answers for a simple request per user as in my
> example?  How you would solve that if not by threading?  Amazon has
> about 30 million products and they have filters similar to what I
> mentioned.  But when clicking on one of the I18n site at the bottom,
> you're taken to another server, which looks like it uses a different
> DB back end (I could be wrong) and you don't get instant translation
> of the category you're looking at.  Their response time is about 3
> seconds on my 10mbs (not cable) download.  As for what programming
> language they use...

Honestly, how WOULD you solve that with threading?  You describe a page that 
needs to be generated that has a half-dozen queries against the database 
ranging from simple to moderately complex, some of which are site-generic and 
some are user-specific.

How does one solve that with threading?  

1) Run the site-generic queries once and cache them in memory and let other 
threads just use that query result.  You can do that without threads.  Just 
render that part of the page and cache that string to disk, to the database, 
or to memcache.  If the memecache server is on the same box then it should be 
identical to the threading version, performance-wise.  (Give or take VM 
considerations.)

2) Push the user-specific DB queries to separate threads so they can run in 
parallel.  All that does is push the hard work off onto the DB server, which is 
still running the same number of queries.  And PHP can't respond until all of 
the queries finish anyway, and the DB server will respond no faster, so you're 
really gaining nothing.

You keep saying "how would you solve this without threads?" as if they're some 
magical speed fairy dust.  Given the scenario you describe, I don't even see 
how threads would buy you anything at all.

Where threads would be useful is for lots of very small writes on rapidly 
changing data.  I would never want to write, say, the World of Warcraft 
servers without threading and a persistent runtime, but then I wouldn't want 
to write them in PHP to begin with.

Insert that old saying about hammers and nails here.

--Larry Garfield

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



[PHP] Constructor usage

2010-04-04 Thread Larry Garfield
Hi folks.  Somewhat philosophical question here.

I have heard, although not confirmed, that the trend in the Java world in the 
past several years has been away from constructors.  That is, rather than 
this:

class Foo {
  public void Foo(Object a, Object b, Object c) {}
}

Foo f = new Foo(a, b, c);

The preference is now for this:

class Foo {
  public void setA(Object a) {}
  public void setB(Object b) {}
  public void setC(Object c) {}
}

Foo f = new Foo(a, b, c);
f.setA(a);
f.setB(b);
f.setC(c);

I suppose there is some logic there when working with factories, which you 
should be doing in general.  However, I don't know if that makes the same 
degree of sense in PHP, even though the OO models are quite similar.

So, I'll throw the question out.  Who uses example 1 above vs. example 2 when 
writing dependency-injection-based OOP?  Why?  What trade-offs have you 
encountered, and was it worth it?

--Larry Garfield

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



Re: [PHP] Constructor usage

2010-04-04 Thread Larry Garfield
On Sunday 04 April 2010 09:21:28 pm Paul M Foster wrote:

> > So, I'll throw the question out.  Who uses example 1 above vs. example 2
> > when writing dependency-injection-based OOP?  Why?  What trade-offs have
> > you encountered, and was it worth it?
> 
> One problem I have with "parameterless constructors" is this: When you
> rely on setters to shape your object rather than the constructor, your
> other methods cannot assume the object is in proper shape to be usable.
> There's no guarantee the programmer won't forget one of the vital
> setters. So each method in the object must test to ensure the object can
> actually be used properly. This isn't a deal-breaker, but it seems like
> an awfully unnecessary piece of additional code which must be replicated
> in each method. (Naturally, this is moot where the class doesn't depend
> on any outside objects or parameters to operate.)

Yeah, I tend toward using constructors for injection for the same reason: That 
way I always know for sure that if I have an object, it's "complete".  I defer 
most object instantiation to factories anyway, so in practice it's not a huge 
issue for me.

> I've found that many of my classes require other classes in order to
> operate. Moreover, they must be instantiated in the proper order, or
> things fall apart. So I took the step of creating my own "dependency
> injection instantiator" class which handles all this for me. Classes
> with dependencies typically are specified so that the requisite objects
> are passed to the constructor (the simplest way). Each class which is
> managed by the DII is registered first, with whatever parameter or
> object dependencies needed. Then the DII's "instantiate()" method is
> called as needed for each object. The DII class handles instantiating
> objects in the proper order and with the proper dependencies. The
> programmer's job is made much simpler.
> 
> Paul

Sounds overly complicated, but whatever works. :-)  In my experience so far I 
find that a well-designed factory is sufficient, but it may not be in larger or 
more involved OO frameworks than I've used to date.

--Larry Garfield

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



Re: [PHP] class attributes and __construct

2010-04-15 Thread Larry Garfield
On Thursday 15 April 2010 08:37:40 am Ashley Sheridan wrote:

> I know I could move it to __construct and give it a default value in the
> arguments list, but that brings it's own problems. What if the argument
> list grows too big, and which attribute would be deemed more important
> than another that you might want to override it without specifying every
> other? Is there a rule of thumb as to what belongs in __construct and
> what does not?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

I tend to favor setting the default with the property itself rather than in 
the constructor, even if I expect the constructor to specify it.  I really 
really hate having undefined variables. :-)  So even if, for instance, I'm 
going to pass in a db connection object in the constructor I will define it in 
the class and set it to NULL rather than not setting to anything.

OK, I'm a little OCD, but it works. :-)  

--Larry Garfield

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



Re: [PHP] iCal parsing and processing

2010-05-25 Thread Larry Garfield
Hm.  Thanks, but it looks like that's all in Python.  I'm not a parcel tongue 
so that wouldn't be much use to me in a PHP app. :-)  Thanks though.

--Larry Garfield

On Tuesday 25 May 2010 06:43:30 pm Jason Pruim wrote:
> Hi Larry,
> 
> Take a look at: http://trac.calendarserver.org/
> 
> It's Apple's open source page which includes their iCal web server...
> Maybe something can be pulled from that?  Just something to think
> about and see if it helps :)
> 
> Also... Not sure if you've looked at the CalDav protocol but that is
> what it basically runs off of so if you haven't checked it out, you
> might get some better results :)
> 
> On May 25, 2010, at 2:10 PM, la...@garfieldtech.com wrote:
> > Hi folks.  I am looking for a good iCal processing library (open
> > source / GPL compatible).  Unfortunately, everything I've been able
> > to find so far is half-assed, incomplete, buggy, or so horribly
> > designed that I'd be embarrassed to use it (or several of the
> > above).  I was hoping someone could recommend one that actually
> > works.  I'd prefer an OO interface as it seems a natural fit, but at
> > this point I'll settle for whatever works.
> >
> > I am not looking for an application with UI and form integration and
> > stuff.  I just want a working stand-alone parser.  (If it can be
> > ripped out of something more complete, that's fine.)
> >
> > My needs:
> > 1) Given raw data (provided by a user form that I can already
> > handle), construct iCal VEVENT information including RRULEs and
> > EXRULEs.
> > 2) Given a VCALENDAR / VEVENT object, generate the appropriate iCal
> > text string that I can write to a file or return to the browser with
> > the appropriate mime header.
> > 3) Given a VCALENDAR / VEVENT object with RRULEs and EXRULEs in it,
> > be able to say "give me the start/end dates of the next X
> > occurrences from some date" or "give me all the start/end dates of
> > occurrences until date Y".
> >
> > What I've found so far:
> >
> > http://www.kigkonsult.se/iCalcreator/ - This is the best I've found
> > so far, and it's what I'm using now.  It's missing requirement #3,
> > though, as near as I can tell.  Actually if I could add that
> > functionality to it without too much trouble I'd probably stick with
> > it, but it's non-trivial functionality.  It's also PHP 4 OO, but I
> > can deal.
> >
> > http://phpicalendar.net/ - This claims to do #3, I think, but it's
> > integrated into a web app.  The code for it is also horrific, as the
> > entire parser is build on include files that rely on global
> > variables without using any functions.  The security implications of
> > that alone scare me to death to say nothing of side effects and
> > stability.
> >
> > http://code.google.com/p/qcal/ - Documentation is sorely lacking, as
> > it is listed as "pre-alpha, real alpha to be released in January".
> > That post was made in December, and there's still no "real
> > alpha". :-)  So I can't really tell if it does what I need or not.
> >
> > A quick search turned up nothing in PEAR, and Zend Framework has
> > only a proposal from 2 years ago, not an actual library.
> >
> > Any others I don't know about?  This seems like an area that cries
> > out for a good standard library, but as of yet I haven't found one
> > that works.  Help or pointers would be much appreciated.
> >
> > --Larry Garfield
> 

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



Re: [PHP] CakePHP, alternatives?

2010-06-05 Thread Larry Garfield
One other thing I will add:

Don't just learn PHP.  Learn Javascript as well.  Don't treat it as PHP 
without dollar signs, but learn Javascript as Javascript, and PHP as PHP.  
Then after you've gotten some time with those, take some time to learn, or at 
least learn about even if you never work with it, Erlang.  Or Haskel. Or some 
other stricter, purely functional language.  Something that works totally 
differently than PHP.

Even if you don't ever use it, the perspective you gain from approaching a 
problem from a different angle will help you learn about the strengths and 
weaknesses of different languages, different ways of thinking, different ways 
of 
leveraging your tools well, etc.

The 6 hours or so I spent reading about Erlang and purely functional languages 
helped my PHP skills considerably, even though I never wrote a single line of 
Erlang.  (I was already very solid in PHP at the time, but it made me even 
better.)

--Larry Garfield

On Saturday 05 June 2010 12:51:47 am Shreyas wrote:
> @ All - Points duly noted. Thanks for all the mighty advice.
> 
> As the owner of the thread, I consider the thread closed for now unless
> anyone has anything to add.
> 
> --Shreyas
> 
> On Sat, Jun 5, 2010 at 1:02 AM, Adam Richardson wrote:
> > > I am reading this PHP for Dummies and then I plan to read Head First
> > > with PHP, MySQL, and Apache. Do you know any books that I can read
> > > online or I can buy? I would be happy to do that.
> >
> > Hi  Shreyas,
> >
> > I think you've received some excellent advice.
> >
> > I like the Head First Books quite a bit.  I attended grad school for
> > cognitive psychology, and I can tell you that the Head First Books do a
> > great job of integrating methods shown to enhance learning.
> >
> > I own several of the books in the series, including those on iPhone
> > development and Design Patterns, and while I don't own the PHP book, I've
> > reviewed it at the book store and recommend it to some friends who have
> > taken up PHP, too, and they've been very pleased with the resource.
> >
> > I hope you have an enriching, enjoyable experience as you learn PHP.
> >
> > Adam
> >
> > --
> > Nephtali:  PHP web framework that functions beautifully
> > http://nephtaliproject.com
> 

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



Re: [PHP] the state of the PHP community

2010-07-28 Thread Larry Garfield
 to bring some sort of 
sanity to the PHP dev process before finally giving up in despair.  I really do 
respect what he was doing and wish he'd been more successful.

- If I still remembered enough C to do so and had time to do so I'd try to 
work on PDO.  Sadly I don't have either.  PDO is in desperate need of help, 
apparently, and everyone is standing around waiting for someone else to do 
something about it.  Given that databases are kinda critical for most PHP apps 
that is a non-small problem.

> Do you network with other PHP'ers in real life - meetups etc, do you
> tend to shy away, or do you find you circulate in other web related but
> non PHP focussed communities?

Mostly my work in the Drupal project eats up 99.9% of my community networking 
time, so I have very little left over for general PHP networking.  I used to 
be somewhat active in the Chicago PHP users group but haven't been for some 
time.

> Are you a member or any other web tech communities, opensource efforts,
> or standardization bodies - again, if so which?

I'm one of the lead developers of Drupal (although the term is very vague in 
the Drupal world), and the Database subsystem maintainer for Drupal 7 and 
later having written most of it.  I am also in my 3rd year as a member of the 
Drupal Association Board of Directors as Director of Legal Affairs.

I was also the lead organizer of the GoPHP5 effort a few years ago that managed 
to finally kill off PHP 4.

In theory I'm the Drupal rep to the "PHP Standards" working group, but I think 
that group has pretty well died.

> Are there any efforts, projects or initiatives which are floating your
> boat right now and that your watching eagerly (or getting involved with)?

Just lots of stuff within the Drupal world, which is large enough to keep me 
busy.  I won't bore you with details.  Come to DrupalCon Copenhagen next month 
if you want such details. :-)

--Larry Garfield

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



Re: [PHP] the state of the PHP community

2010-07-29 Thread Larry Garfield
On Thursday 29 July 2010 02:07:58 am you wrote:

> Hi Larry,
> 
> Thanks for taking the time to reply, a solid insightful one at that -
> kudos +1 for your opensource drupal efforts!
> 
> Good of you to mention, and indeed to see, Palinter grasping opensource
> with two hands, this is certainly a very credible approach to business
> which deservedly reaps good rewards; testament to this is Day Software
> (including of course Roy T. Fielding) which it seems is just about to be
> bought by Adobe, a big +1 for this approach; and one I hope to see more of.
> 
> With regards drupal development, there is a rather interesting chap
> called Stéphane Corlosquet [ http://drupal.org/user/52142 ] who does a
> fair bit of committing and really pushes the semantic web / linked data
> side of drupal - definitely worth keeping tabs on.

Oh I'm familiar with Scor.  I've talked with him before about a project I'm 
working on that is using the amorphous, ill-defined beast known as RDF. :-)

--Larry Garfield

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



Re: [PHP] CMS plugin support

2010-10-22 Thread Larry Garfield
On Friday, October 22, 2010 4:30:06 am Emil Guy wrote:
> Hi!
> 
> I have a bit of a vague question. I have always used different selfmade
> basic "CMS" for web pages. That works fine, and I like having my own
> structure and light code weight. But the big pro with using a standard CMS
> like drupal is the plugin support. Are there any php plugin standards or is
> there a doable way of implementing support for drupal (joomla, whatever)
> plugs? Of course there are php libraries, but I would like something more
> lika a visual gadget and extremly fast implementation. I created a
> wordpress blog instead of using my own code a while ago, and implementing
> twitter support, antispam, etc was just two clicks and 2 min work, instead
> of reading a manual for a library and maybe half an hour an hour work
> implementing and debugging. And that was a nice change.
> 
> When you make normal simple web pages do you guys use a ready-made CMS as a
> base or do you have a self-made php template, or self-made cms, or what
> solutions do you use?
> 
> Kind Regards Emil Edeholt

The ready availability of a bajillion plugins and a large community of people 
who can support me in writing more is one of the key reasons that virtually 
all of my web work these days uses Drupal.  AFAIK there is no cross-CMS plugin 
system in PHP, and given how architecturally different various systems are I 
don't know that one would even be possible.

--Larry Garfield

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



[PHP] Disk IO performance

2010-11-28 Thread Larry Garfield
There are many things that everybody "knows" about optimizing PHP code.  One 
of them is that one of the most expensive parts of the process is loading code 
off of disk and compiling it, which is why opcode caches are such a bit 
performance boost.  The corollary to that, of course, is that more files = 
more IO and therefore more of a performance hit.

But... this is 'effin 2010.  It's almost bloody 2011.  Operating systems are 
smart.  They already have 14 levels of caching built into them from hard drive 
micro-controller to RAM to CPU cache to OS.  I've heard from other people (who 
should know) that the IO cost of doing a file_exists() or other stat calls is 
almost non-existent because a modern OS caches that, and with OS-based file 
caching even reading small files off disk (the size that most PHP source files 
are) is not as slow as we think.

Personally, I don't know.  I am not an OS engineer and haven't benchmarked 
such things, nor am I really competent to do so.  However, it makes a huge 
impact on the way one structures a large PHP program as the performance trade-
offs of huge files with massive unused code (that has to be compiled) vs the 
cost of reading lots of separate files from disk (more IO) is highly dependent 
on the speed of the aforementioned IO and of compilation.

So... does anyone have any actual, hard data here?  I don't mean "I think" or 
"in my experience".  I am looking for hard benchmarks, profiling, or writeups 
of how OS (Linux specifically if it matters) file caching works in 2010, not 
in 1998.

Modernizing what "everyone knows" is important for the general community, and 
the quality of our code.

--Larry Garfield

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



  1   2   3   4   5   >