Re: [PHP] framework or not

2013-10-23 Thread Larry Martell
On Wed, Oct 23, 2013 at 10:26 AM, Tedd Sperling tedd.sperl...@gmail.comwrote:

 On Oct 23, 2013, at 12:04 AM, Robert Cummings rob...@interjinn.com
 wrote:

  On 13-10-22 05:38 PM, Larry Garfield wrote:
  If you need more convincing, I will cite Fred Brooks:
 
  http://www.cs.nott.ac.uk/~cah/G51ISS/Documents/NoSilverBullet.html
 
  Excellent article, thanks for the pointer. So many assertions have stood
 the test of time thus far.
 
  Cheers,
  Rob.

 Yes, it was an excellent article.

 One of the things I liked about the article was the concept of
 Incremental Development, which is something I have practiced since the
 Old Apple ][ days (Incidentally, he states he learned of this in 1958 -- is
 that a typo?).

 In 1977, I started many of my programs with (pardon my failing memory of
 AppleSoft syntax):

 Gosub GatherData()
 Gosub ProcessData()
 Gosub PresentDate()
 END

 It ran, but didn't do anything. Incidentally, that resembles a one-pass
 MVC design, does it not?

 In any event, I would flesh out the code until I got what I wanted.

 Maybe that's one of the reasons why Android or iOS Development starts with
 a Default Hello World App that does very little than run.

 Start simple, develop complex.


Is there any other way to do it? I've been programming since 1975 and
that's what I was taught and that's how always do it.

Was it Brian Kernighan who said the 3 rules of programming are:

1. Keep it simple.
2. Build it in stages.
3. Let someone else do the hard part.


Re: [PHP] framework or not

2013-10-23 Thread Larry Martell
On Wed, Oct 23, 2013 at 11:08 AM, Tedd Sperling tedd.sperl...@gmail.comwrote:

 On Oct 23, 2013, at 12:34 PM, Larry Martell la...@software-horizons.com
 wrote:
  Was it Brian Kernighan who said the 3 rules of programming are:
 
  1. Keep it simple.
  2. Build it in stages.
  3. Let someone else do the hard part.

 Sounds good to me.

 I would also add:

 I've learned something new everyday of my life -- and I'm getting damned
 tired of it.

 I'm looking forward to the day that I'll know everything and can stop all
 this learning nonsense.


Everything that can be invented has been invented.
-Charles H. Duell, Commissioner of US patent office, 1899.


Re: [PHP] Friday's Question

2013-09-20 Thread Larry Martell
On Fri, Sep 20, 2013 at 11:35 AM, Joshua Kehn josh.k...@gmail.com wrote:
 On Sep 20, 2013, at 1:26 PM, Larry Martell la...@software-horizons.com 
 wrote:

 On Fri, Sep 20, 2013 at 11:24 AM, Joshua Kehn josh.k...@gmail.com wrote:


 Slightly snobbish solution: Don't use windows.

 Unfortunately required to VPN into most of my clients corporate networks.

 Windows is required to VPN in? I'm guessing they use some proprietary client 
 then? --jk

Yes, and/or they validate the host ID, and/or there's some soft key
RSA thing involved.

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



Re: [PHP] Friday's Question

2013-09-20 Thread Larry Martell
On Fri, Sep 20, 2013 at 10:51 AM, Tedd Sperling t...@sperling.com wrote:
 Hi gang:

 Do you use a Mousepad?

 My reason for asking is that I've used a Mousepad ever since mice first came 
 out (back when they had one ball).

 Now that mice are optical (no balls), Mousepads are not really needed -- or 
 so I'll told by the college -- you see, they don't provide Mousepads for 
 their student's computers.

 As such, I wondered what's the percentage of programmers still using a 
 Mousepad?

 Secondly, are Mousepads used primarily by older programmers (like me) while 
 younger programmers don't use Mousepads, or what?

 So -- please respond with:

 Age: *
 Mousepad: Yes/No

54 Yes

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



Re: [PHP] Friday's Question

2013-09-20 Thread Larry Martell
On Fri, Sep 20, 2013 at 11:16 AM, Joshua Kehn josh.k...@gmail.com wrote:
 On Sep 20, 2013, at 1:04 PM, Daniel Brown danbr...@php.net wrote:

I'm in my mid-thirties and - despite having an optical mouse - I
 do indeed still use a mousepad.  A customized one that the wife did
 for me for Christmas one year: images of Futurama, the Cleveland
 Browns, Minnesota Vikings, and several aircraft, all surrounding a
 picture of her and our daughter.  I've found that shiny surfaces -
 such as my desk - reflect too much of the laser, causing the mouse to
 be far less responsive.

 I'm in my 20's and rarely, if ever, use a dedicated mouse. I've transitioned 
 to having all my workstations be laptops of one sort or another and they have 
 built-in trackpads. Of course I also rarely use the mouse when there are so 
 many keyboard shortcuts available.

When I'm on my MacBook (which is most of the time) I use the trackpad.
But in the unfortunate times I have to be on a Windows box I always
connect a mouse.

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



Re: [PHP] Friday's Question

2013-09-20 Thread Larry Martell
On Fri, Sep 20, 2013 at 11:20 AM, Jen Rasmussen j...@cetaceasound.com wrote:
 -Original Message-
 What in the heck is a Bag Bomb?

It's a salve for cow udders. Not sure what a person would do with it.

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



Re: [PHP] Friday's Question

2013-09-20 Thread Larry Martell
On Fri, Sep 20, 2013 at 11:24 AM, Joshua Kehn josh.k...@gmail.com wrote:

 On Sep 20, 2013, at 1:23 PM, Larry Martell la...@software-horizons.com 
 wrote:

 On Fri, Sep 20, 2013 at 11:16 AM, Joshua Kehn josh.k...@gmail.com wrote:

 I'm in my 20's and rarely, if ever, use a dedicated mouse. I've 
 transitioned to having all my workstations be laptops of one sort or 
 another and they have built-in trackpads. Of course I also rarely use the 
 mouse when there are so many keyboard shortcuts available.

 When I'm on my MacBook (which is most of the time) I use the trackpad.
 But in the unfortunate times I have to be on a Windows box I always
 connect a mouse.

 Slightly snobbish solution: Don't use windows.

Unfortunately required to VPN into most of my clients corporate networks.

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



Re: [PHP] PHP vs JAVA

2013-08-20 Thread Larry Garfield

On 8/20/13 9:00 AM, Tedd Sperling wrote:

Hi guys:

A teacher at my college made the statement that JAVA for Web Development is 
more popular than PHP.

Where can I go to prove this right or wrong -- and/or -- what references do any 
of you have to support your answer? (sounds like a teacher, huh?)

Here are my two references:

http://w3techs.com/technologies/details/pl-php/all/all

http://w3techs.com/technologies/history_overview/programming_language/ms/y

But I do not know how accurate they are.

What say you?

Cheers,


tedd


As others have said, he's simply wrong. :-)  Goodness of either 
language aside, the data (W3Techs is what I usually cite) is clear: For 
server-side web dev, PHP is the 800 lb gorilla.


For all programming combined?  Java may be bigger than PHP, sure.  For 
embedded?  No question, Java  PHP as PHP has almost no presence.  For 
enterprise shops?  There probably are segments of the market that are 
very Java-centric, even on the web, no question.


It's all how you define your scope.  I'm sure he could come up with some 
definition of market that would show Java having a bigger marketshare 
than PHP, within that market.  The question is whether that is a valid 
definition of market in context.


Lies, damned lies, and statistics. :-)

As countering data-points: Wordpress alone is 18% of the web.  Drupal is 
the #1 CMS used to power US government websites.  Universities and 
Museums are very big on Drupal.  (That's my day job. g)  PHP's 
marketshare is huge, even in enterprise.


--Larry Garfield

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



Re: [PHP] how old is this version of PHP?

2013-08-19 Thread Larry Garfield

On 08/17/2013 06:26 PM, Camilo Sperberg wrote:

On 16 aug. 2013, at 19:17, Tamara Temple tamouse.li...@gmail.com wrote:


Looking into a problem for someone who is using Godaddy Shared Web Hosting (I 
know..), I noticed the version tag reported by phpinfo is:


PHP API 20041225
PHP Extension   20060613
Zend Extension  220060519

Just how old is this version of PHP??



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


According to my google search, it should be 5.2.9, so it isn't that old:


5.2.9 was released in February of 2009.  5.2 is completely retired and 
out of support.  5.3 is on security-only life-support.  5.4 is the 
legacy stable release.


Yes, 5.2.9 IS that old. :-)  Really, get a host that has made it into 
this decade.  (GoDaddy apparently doesn't meet that qualification.) 
You're doing clients a disservice by allowing them to run such an 
ancient and unsupported version.


--Larry Garfield

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



Re: [PHP] how old is this version of PHP?

2013-08-19 Thread Larry Garfield
Far too much is made of BC breaks between PHP versions.  Well-behaved 
code should still be working a decade later.


The catch is that well behaved gets tighter each release.  For example:

$foo = hello;
$bar = world;
print $foo[$bar];

In PHP 5.3 and earlier, $bar is a string which makes no sense as an 
index of a string.  It needs to be an int.  PHP therefore casts that to 
an int, gets 0, and you get h.


In PHP 5.4, that was acknowledged as a bug (which it always was), and 
now triggers a Warning.  Because, really, it always was a bug but just 
failed silently before.  Now it tells you so you can fix it.  It looks 
like a BC break, though, because I get an error I didn't used to.


Other things are, eg, removing register_globals and magic_quotes, which 
have been deprecated for about 12 years and if you were still using them 
now then your code should break. :-)  They're a security hole.  But 
those are very few and far between.


--Larry Garfield

On 8/19/13 7:25 AM, Jeff Burcher wrote:


I apologize if this is off topic, but this raises a question for me. Why
can't new versions be backwards compatible? Is it really that difficult to
accomplish? This has been a complaint of mine for years with Windows ever
since we went from 95 to 98. I am an AS400 programmer and I have legacy
programs written in RPG II, which died 20 years ago, and they still run fine
on the newest version of AS400 or iSeries or Power System or whatever the
heck it is called now. I also have PHP scripts that are many years old that
work just fine the way they are, if a new version doesn't come along and
make me have to reprogram for no reason just because it can't handle older
code. Really, have Do loops and data calls changed that much over the years?
I mean, all you do is set a condition, use a variable key field, and voila,
data is pulled and processed, no big deal. Yeah, you can get fancy with it,
but the core basics are still the same. I have been programming for over 35
years and like to think that once a program is built it should run forever.
Do we just accept that we have to rewrite every program we ever wrote every
time a new version comes out? A little extreme, but you get my point.
Comments? Suggestions?

(I am also the kind of guy who thinks quality made hand tools from the 1800s
are superior to many purchased today at Lowes or Home Depot.)

Thanks,

Jeff Burcher - IT Dept
Allred Metal Stamping Works
Making Metal Parts since 1946.



-Original Message-
From: Lester Caine [mailto:les...@lsces.co.uk]
Sent: Monday, August 19, 2013 6:24 AM
To: php-general@lists.php.net
Subject: Re: [PHP] how old is this version of PHP?

Larry Garfield wrote:

5.2.9 was released in February of 2009.  5.2 is completely retired and
out of support.  5.3 is on security-only life-support.  5.4 is the

legacy stable

release.


Yes, 5.2.9 IS that old. :-)  Really, get a host that has made it into
this decade.  (GoDaddy apparently doesn't meet that qualification.)
You're doing clients a disservice by allowing them to run such an
ancient and unsupported version.


While the statements are correct, many users are not in a position to move
from their currently working systems to even 5.3 let alone 5.4. There is

still a

lot of legacy code that unless a few more people step up and help bring it
forward for the many - non programming - users who are stuck with legacy
applications, they will remain requiring 5.2 to run. ISPs got caught out

when

they arbitrarily moved accounts forward, and GoDaddy have even been
caught by that, so maintaining a LTS version of PHP5.2 is the lesser evil

...

Windows 2000 is supposed to be dead, but *I* still have sites reliant on

it

because the code and hardware is unsupported in even XP. Saying
something is dead only works if there is an affordable way of moving

forward

;)

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve -
http://enquirysolve.com/ Model Engineers Digital Workshop -
http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

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







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



Re: [PHP] POST action

2013-08-01 Thread Larry Garfield

On 7/29/13 3:02 PM, Paul M Foster wrote:

On Mon, Jul 29, 2013 at 11:50:01AM -0500, Larry Garfield wrote:


On 7/28/13 9:23 PM, Paul M Foster wrote:

On Sun, Jul 28, 2013 at 08:46:06PM -0500, Larry Garfield wrote:


[snip]



Except as noted above. This is all home-grown, using native PHP
functions designed to do these things, and classes I've written. I
carefully examine each field when writing the POST-handling code with
the idea in mind that no matter what the HTML says, the return value
must conform to what *I* think it should be. No MVC framework written by
others (though I do conform to MVC paradigm).

Paul


Then you're not writing your own form tags from the sound of it;
you're writing your own Form API.  Still an improvements. :-)


No, I'm writing the form tags as well. I write the whole thing, soup to
nuts. But as I'm writing the back end validation stuff, I realize that
what I wrote in the HTML doesn't matter when it comes to hackers and
script kiddies. So I use my bless and validation libraries to tackle
form responses. That's the point I'm making. I understand what you're
saying about using someone else's framework so you can make sure that
tested code is being used to ensure against hacking attempts. But your
pronouncement was so thunderous that I had to provide the exception. If
you hang around here and read a book or two on security, you can write
your own code that handles this stuff. Particularly if you have an
example like CodeIgniter to use, to see how it's done.

(There are times when I *don't* write the HTML. My wife the designer
does. But I still go in and modify it to provide the validation bits
which she can't do. She uses Dreamweaver, so a lot of the time, she
doesn't even know what the raw HTML looks like.)

Paul


So you're writing your own form tags for each specific time you need a 
form, or you wrote your own form builder API that is writing the form 
tags for you?


Because if the former, I claim it's insecure.  The development process 
is insecure, so you will screw up sooner or later.  You're only human.


--Larry Garfield

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



Re: [PHP] POST action

2013-07-29 Thread Larry Garfield

On 7/28/13 9:23 PM, Paul M Foster wrote:

On Sun, Jul 28, 2013 at 08:46:06PM -0500, Larry Garfield wrote:


On 07/28/2013 12:38 PM, Ashley Sheridan wrote:

On Sun, 2013-07-28 at 13:37 -0400, Jim Giner wrote:



Never write your own form?  I'm guilty - oh, so guilty.  What exactly is
a 'security hardened' form?


- All forms need a valid CSRF token to avoid CSRF attacks.  This
needs to be matched between the submitted form and server-maintained
state.  Do all of your forms have that?  Every single one?  (A GET
lookup form like a search box doesn't need it, but anything with
POST does, I'd argue.)


Yes. I wrote a bless class just for this purpose, which I use on all
form pages.



- Do you have a select element? Do you have error handling for when
someone submits a value for that wasn't one of the option elements?


Yes, since I realize that what comes back to me may bear no resemblence
to what I coded in HTML. Thus, I always check for allowed SELECT
values.



- Your text input field has a max length of 20. Does your code
return an error when the user enters a string of 100 characters?


Yes. Same answer. Putting a max length of 20 in the HTML works okay, but
the user could still submit something much longer if they are attempting
to hack the page. Thus I always check for max characters on the return.



- Are you checking for weird edge-case-y character encoding issues?
(Some versions of some browsers can be hacked by sending UTF-7
instead of UTF-8 for certain parts of the request. I don't fully
understand that stuff myself, either.)


No I don't check for this.



- You have a number field (HTML5).  Does your PHP code handle
someone submitting a string anyway?


I don't use HTML5 tags like this, since they are not universally
supported. However, I check that numbers look like numbers on return and
strings look like strings on return. PHP has built-in functions for
this.

All this is part of my validation class.



- Are you checking all of those correctly every single time you
write a form?


Except as noted above. This is all home-grown, using native PHP
functions designed to do these things, and classes I've written. I
carefully examine each field when writing the POST-handling code with
the idea in mind that no matter what the HTML says, the return value
must conform to what *I* think it should be. No MVC framework written by
others (though I do conform to MVC paradigm).

Paul


Then you're not writing your own form tags from the sound of it; you're 
writing your own Form API.  Still an improvements. :-)


Now, let's talk about form accessibility...

--Larry Garfield

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



Re: [PHP] POST action

2013-07-28 Thread Larry Garfield

On 07/28/2013 12:14 PM, iccsi wrote:

form action=action.php method=post
pYour name: input type=text name=name //p
pYour age: input type=text name=age //p
pinput type=submit //p
/formIn the PHP tutorial manual, it says that we can have post 
action to the form itself just like above coding.I would like to know 
in the real projects, can we have action to the same PHP file, since 
that we only need have one filebut not 2 files foe POST request,Your 
help and information is great appreciated,regards,Iccsi,


Real projects to all kinds of things.  Which is best depends on who 
you ask. :-)


I would argue that there's 3 good approaches, both of which are viable:

1) Define your form abstractly via an API, and have the API detect the 
presence of POST request and then process the form after it's built.  
That means you do submit back to the same URL.  (Drupal 7 and earlier do 
this.)


2) Put 2 separate request handlers / controllers at the same path, one 
for GET and one for POST.  So you submit back to the same URL but an 
entirely different piece of code responds to it.  (This requires a good 
routing system that can differentiate between GET and POST.)


3) Every form is defined as its own object somewhere with a unique ID.  
All forms post to the same URL but include the form ID.  Code at that 
URL looks up the form object by ID and maps the submitted data to it to 
know what to do with it.


Note that in all 3 cases you're defining a form via an API of some 
kind.  You are not writing form tags yourself.  Don't do that. Ever.  I 
promise you that you will have a security hole or six if you do.  Use a 
good form handling API for building forms.  That's what good Real 
projects do.  There are a lot out there.  Most fullstack frameworks or 
CMSes have one built in (I know Drupal and Code Ignighter do, although 
they're quite different), and there are reasonably stand-alone 
components available in both Symfony2 Components and Zend Framework.  
Please don't write your own.  There are too many good ones (and even 
more bad ones, of course) already out there that have been security 
hardened.


--Larry Garfield

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



Re: [PHP] POST action

2013-07-28 Thread Larry Garfield

On 07/28/2013 12:38 PM, Ashley Sheridan wrote:

On Sun, 2013-07-28 at 13:37 -0400, Jim Giner wrote:



Never write your own form?  I'm guilty - oh, so guilty.  What exactly is
a 'security hardened' form?


- All forms need a valid CSRF token to avoid CSRF attacks.  This needs 
to be matched between the submitted form and server-maintained state.  
Do all of your forms have that?  Every single one?  (A GET lookup form 
like a search box doesn't need it, but anything with POST does, I'd argue.)


- Do you have a select element? Do you have error handling for when 
someone submits a value for that wasn't one of the option elements?


- Your text input field has a max length of 20. Does your code return an 
error when the user enters a string of 100 characters?


- Are you checking for weird edge-case-y character encoding issues? 
(Some versions of some browsers can be hacked by sending UTF-7 instead 
of UTF-8 for certain parts of the request. I don't fully understand that 
stuff myself, either.)


- You have a number field (HTML5).  Does your PHP code handle someone 
submitting a string anyway?


- Are you checking all of those correctly every single time you write a 
form?


Remember, a form POST is not a form submission.  It's a wide open RPC 
call for the entire Internet, for which you provide casual suggestions 
via HTML.  Always assume an attacker bypasses the HTML and just POSTs 
variables right at your server.  I'm probably forgetting a few things in 
the list above, too.


Hence, for 98% of cases, if you're writing your own form and input 
tags, you're doing it wrong. :-)  Maybe you end up with your own PHP 
library to do that for you that handles all of the above, but... why, 
when there are so many already that do a better job than you can on your 
own (because they've had dozens of smart people including security 
experts working on them)?



I would say code forms on your own first, as a learning experience, then
use frameworks once you know what you're doing.


That I'll agree with.  Do it manually for the learning, then use a 
battle-hardened tool for real work is a generally good approach to many 
things in programming.


--Larry Garfield

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



Re: [PHP] /tmp/directory

2013-07-22 Thread Larry Martell
On Mon, Jul 22, 2013 at 9:59 AM, Larry Martell
la...@software-horizons.com wrote:
 On Mon, Jul 22, 2013 at 9:50 AM, Tedd Sperling tedd.sperl...@gmail.com 
 wrote:
 On Jul 22, 2013, at 11:20 AM, Tedd Sperling t...@sperling.com wrote
 Hi gang:

 I should know this, but I don't.

 Where is the /tmp/ directory?

 You see, I have a client where his host has apparently changed the /tmp/ 
 directory permissions such that old php/mysql scripts cannot write to the 
 /tmp/ directory anymore -- they did at one time.

 So, how do I fix it?

 Cheers,

 tedd

 Let me add -- the PHP version I am working with is 4.3.10.

 I know...

 df /tmp should show you where it's mounted.

And sys_get_temp_dir() will tell you the path.

# php
?
print sys_get_temp_dir()
?

/tmp

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



Re: [PHP] /tmp/directory

2013-07-22 Thread Larry Martell
On Mon, Jul 22, 2013 at 9:50 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Jul 22, 2013, at 11:20 AM, Tedd Sperling t...@sperling.com wrote
 Hi gang:

 I should know this, but I don't.

 Where is the /tmp/ directory?

 You see, I have a client where his host has apparently changed the /tmp/ 
 directory permissions such that old php/mysql scripts cannot write to the 
 /tmp/ directory anymore -- they did at one time.

 So, how do I fix it?

 Cheers,

 tedd

 Let me add -- the PHP version I am working with is 4.3.10.

 I know...

df /tmp should show you where it's mounted.

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



Re: [PHP] Split/Group date together.

2013-07-18 Thread Larry Garfield
If I understand you correctly, I call what you're trying to do PHP 
group by, and did a write up on it a few years back:


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

--Larry Garfield

On 7/18/13 8:43 AM, Karl-Arne Gjersøyen wrote:

Hello again.
In my program I have this:

mysql SELECT * FROM transportdokument WHERE dato = '16/7/2013' AND dato
= '18/7/2013';

This list all reccrds for 3 days. I need a way to split it up for every day
even when the requst is as above and don't know in what way I can do it.

I like to have all records for day 16 in one table in PHP/HTML and all
records for day 17 in another table.
i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows.

I hope for your help and advice to do also this correct.

Thank you for your time and effort!

Karl



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



Re: [PHP] json stream filter

2013-06-22 Thread Larry Garfield

On 06/20/2013 04:26 AM, Markus Staab wrote:

Hi!

first post on the list, so please bare with me ;-)

we are handling a lot of cache files in our apps and use json to persist
those contents on the filesystem, because it seems to be the fastest
possible way to read/write files with PHP.

Since I discovered stream-filters, http://www.php.net/manual/en/filters.php,
we use those also for base64 encoding files before sending them over the
wire, which preserves a lot of memory and allows even bigger files.

Would it make sense to also have a native stream filter for fileformats
like JSON, to get maximum performance for reading/writing those (and also
to be able to write big files)?

Thanks,
Markus


What would it do, exactly?  Stream filters still have to read/write a 
string, don't they?  Unless you're talking about reading directly into a 
nested array structure (what json_decode() does), I am not sure what the 
benefit is of what you're describing.  (And I'm not sure you could do 
that, although it would be neato if you could.)


--Larry Garfield

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



Re: [PHP] ODBC

2013-05-19 Thread Larry Martell
On Sun, May 19, 2013 at 9:06 AM, georg georg.chamb...@telia.com wrote:
 Actually who the heck has put SELinux in my machine ?

 anyone knows (is this a part of fedora ?)

Never used Fedora, but it's part of Red Hat and Centos, so would guess
it's also part of fedora. You can disable SELinux with this:

echo 0  /selinux/enforce

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



Re: [PHP] A Good OOP Tutorial/Read?

2013-05-16 Thread Larry Garfield

On 05/16/2013 06:45 PM, Tedd Sperling wrote:

Thanks to both Bastien and Sebastian:

While I understand that an interface is like an abstract Class, in that you 
don't have to flesh-out your methods, but rather where you define exactly how 
Classes who implement that interface will be required to flesh-out those 
methods. But so what? What's the point?

Without giving me complicated examples, just give me one simple example that 
illustrates the advantage of using an interface over writing a new Class where 
you flesh-out whatever methods you want. After all, an interface requires the 
same thing, does it not?

As such, I just don't see the advantage interfaces bring.

Cheers,

tedd


Practical example, PSR-3:

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md

Say you're writing a stand-alone library, maybe a Twitter-connecting 
library.  You want to be able to log stuff, but don't want to have to 
deal with opening log files yourself.  You also want to allow your 
library to be used by people running Symfony, Code Igniter, Drupal, Zend 
Framework, or PHPBB, all of which have their own logging systems in 
place that may talk to syslog, a database, files on disk, or whatever.  
People using those frameworks don't want your library spewing log files 
all over their file system.


Instead, you simply support the PSR-3 logging interface.  You accept an 
object that implements that interface in your constructor, and then 
write to it.  What happens on the other side?  Who gives a damn!


For your own testing, you can write a simple class that implements that 
interface and dumps log messages to disk.


When someone uses your library with Symfony, they just pass in a Monolog 
object (the logging system used by Symfony), and your code is now 
logging errors to whatever they have Monolog configured to do.


When someone uses your library with Drupal, they just pass in the Drupal 
Watchog logger object (which is being rewritten to use PSR-3 as we 
speak), and now your library is logging errors to Drupal's logging 
system (which could be syslog or a DB table, depending on how the user 
has their site configured).


And you don't give a damn about any of that.  All you care about is that 
you support any object that matches this interface.  What that object 
does with the messages you send it, and where that object came from, you 
don't have to give a crap about.


Now take that same concept and apply it at a smaller scale, within your 
own project.  Swap out your database-based cache system for a 
memcache-based one.  Your code doesn't change, because it's writing to 
an interface, not to the database.  Swap out your data store with one 
that is used just for testing.  Etc.


That's what interfaces give you.  Loose coupling, and the ability to 
divide-and-conquer... and even let someone else solve problems for you. :-)


--Larry Garfield

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



Re: [PHP] Problems with array_push?

2013-05-07 Thread Larry Martell
On Tue, May 7, 2013 at 3:06 PM, Jay Blanchard
jay.blanch...@sigmaphinothing.org wrote:
 I know that I must be missing something really ridiculous, but when I
 print_r these arrays they are empty. I have confirmed that $arrayElement is
 properly formed, it just seems that array_push is not working. I know I have
 done this before, but I cannot find my older code. Can someone clear the mud
 from my eyes?

 $issueDifferently = array();
 $issueProblem = array();
 $issueComment = array();

 function addToArray($id, $namecred, $product, $level, $type, $message) {
 $arrayElement = $id
 .'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message;

 if('DoDifferently' == $type) {
 array_push($issueDifferently, $arrayElement);
 } elseif ('Problem' == $type){
 array_push($issueProblem, $arrayElement);
 } elseif ('Comments' == $type) {
 array_push($issueComment, $arrayElement);
 }
 }
 print_r($issueDifferently);
 print_r($issueProblem);
 print_r($issueComment);

You have to declare the arrays as global inside your function.

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



Re: [PHP] ?=$var?

2013-04-18 Thread Larry Martell
On Wed, Apr 17, 2013 at 5:02 PM, Micky Hulse rgmi...@gmail.com wrote:
 On Wed, Apr 17, 2013 at 3:59 PM, Micky Hulse rgmi...@gmail.com wrote:
 You might need to turn on the short tag option
 in your conf file.

 Sorry, ini file, not conf. Been a long day. :D

 I guess I should have asked if short tags are turned on for your 5.3.3?

That was it. Thanks!!

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



Re: [PHP] Date weirdness

2013-04-18 Thread Larry Martell
On Thu, Mar 28, 2013 at 3:40 PM, Larry Martell larry.mart...@gmail.com wrote:
 On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples sstap...@mnsi.net wrote:
 I think I am losing my mind. I have some time zone converting code, and I
 just don't understand what I am seeing. Also my system seems to return the
 wrong time after I do some date operations on unrelated objects.

 This is from a machine that is in eastern time. I want to convert to, for
 example central time:

 $ndate = new Date(date(Y-m-d H:i:s));
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07  - this is the correct time

 $ndate-setTZbyID(EDT);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07 - still correct

 $ndate-convertTZbyID(US/Central);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 10:35:07 - this is wrong it should be 14:35:07

 $xdate = new Date(date(Y-m-d H:i:s));
 echo $xdate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 19:35:07 - HUH? This is wrong - should be 15:35:07

 What in the world is going on here?


 I found this function a while back when I was converting UTC to EST... 
 simple task I know, but still...

 ( I am sorry to whomever wrote this, I didn't keep the source where I found 
 it )

 function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
 'America/Toronto')
 {
 $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
 $time_object-setTimezone(new DateTimeZone($to_tz));
 return $time_object-format('Y-m-d H:i:s');
 }

 I don't seem to have the DateTime object. We are running 5.1.6 and
 that was added in 5.2.0. We are getting the Date module from an
 external extension. I'll have to see about upgrading.

I've upgraded to 5.3.3, got rid of the external Date extension and
implement your solution. It's working perfectly. Thanks much!

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



[PHP] ?=$var?

2013-04-17 Thread Larry Martell
Continuing in my effort to port an app from PHP version 5.1.6 to
5.3.3, the app uses this construct all over the place when building
links:

?=$var?

I never could find any documentation for this, but I assumed it was
some conditional thing - use $var if it's defined, otherwise use
nothing. In 5.1.6 it seems to do just that. But in 5.3.3 I'm not
getting the value of $var even when it is defined. Has this construct
been deprecated? Is there now some other way to achieve this?

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



[PHP] timezone

2013-04-15 Thread Larry Martell
I have a client that has an app the runs with PHP 5.1.6. They want to
upgrade to 5.3.3. First issue I ran into, they have a line of code
that is:

$deftz = date(T);

I'm getting this for that line:

[Mon Apr 15 10:44:16 2013] [error] [client 10.7.14.21] PHP Warning:
date(): It is not safe to rely on the system's timezone settings. You
are *required* to use the date.timezone setting or the
date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely
misspelled the timezone identifier. We selected 'America/Denver' for
'MDT/-6.0/DST' instead in /home/www/itrade-dev/defs.inc on line 349

So I changed it to

$deftz = date.timezone;

and now I get:

[Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
Use of undefined constant date - assumed 'date' in
/home/www/itrade-dev/defs.inc on line 349
[Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
Use of undefined constant timezone - assumed 'timezone' in
/home/www/itrade-dev/defs.inc on line 349

Why is this undefined?

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



Re: [PHP] timezone

2013-04-15 Thread Larry Martell
On Mon, Apr 15, 2013 at 11:17 AM, Jonathan Sundquist
jsundqu...@gmail.com wrote:



 On Mon, Apr 15, 2013 at 12:14 PM, Larry Martell larry.mart...@gmail.com
 wrote:

 I have a client that has an app the runs with PHP 5.1.6. They want to
 upgrade to 5.3.3. First issue I ran into, they have a line of code
 that is:

 $deftz = date(T);

 I'm getting this for that line:

 [Mon Apr 15 10:44:16 2013] [error] [client 10.7.14.21] PHP Warning:
 date(): It is not safe to rely on the system's timezone settings. You
 are *required* to use the date.timezone setting or the
 date_default_timezone_set() function. In case you used any of those
 methods and you are still getting this warning, you most likely
 misspelled the timezone identifier. We selected 'America/Denver' for
 'MDT/-6.0/DST' instead in /home/www/itrade-dev/defs.inc on line 349

 So I changed it to

 $deftz = date.timezone;

 and now I get:

 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant date - assumed 'date' in
 /home/www/itrade-dev/defs.inc on line 349
 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant timezone - assumed 'timezone' in
 /home/www/itrade-dev/defs.inc on line 349

 Why is this undefined?

  You need to set the default time zone in this fashion,

 http://php.net/manual/en/function.date-default-timezone-set.php

But I don't know the timezone - I'm trying to get it so I can convert
times I get from the database to a user requested timezone.

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



Re: [PHP] timezone

2013-04-15 Thread Larry Martell
On Mon, Apr 15, 2013 at 11:33 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 You don't know which timezone the server is in? That's what it wants.

No, I don't - this app runs in different locations all over the world.


 Larry Martell larry.mart...@gmail.com wrote:

 On Mon, Apr 15, 2013 at 11:17 AM, Jonathan Sundquist
 jsundqu...@gmail.com wrote:



 On Mon, Apr 15, 2013 at 12:14 PM, Larry Martell larry.mart...@gmail.com
 wrote:

 I have a client that has an app the runs with PHP 5.1.6. They want to
 upgrade to 5.3.3. First issue I ran into, they have a line of code
 that is:

 $deftz = date(T);

 I'm getting this for that line:

 [Mon Apr 15 10:44:16 2013] [error] [client 10.7.14.21] PHP Warning:
 date(): It is not safe to rely on the system's timezone settings. You
 are *required* to use
 the date.timezone setting or the
 date_default_timezone_set() function. In case you used any of those
 methods and you are still getting this warning, you most likely
 misspelled the timezone identifier. We selected 'America/Denver' for
 'MDT/-6.0/DST' instead in /home/www/itrade-dev/defs.inc on line 349

 So I changed it to

 $deftz = date.timezone;

 and now I get:

 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant date - assumed 'date' in
 /home/www/itrade-dev/defs.inc on line 349
 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant timezone - assumed 'timezone' in
 /home/www/itrade-dev/defs.inc on line 349

 Why is this undefined?


 You need to set the default time zone in this fashion,

 http://php.net/manual/en/function.date-default-timezone-set.php


 But I don't know the timezone - I'm trying to get it so I can convert
 times I get from the database to a user requested timezone.

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



Re: [PHP] timezone

2013-04-15 Thread Larry Martell
On Mon, Apr 15, 2013 at 11:35 AM, Larry Martell larry.mart...@gmail.com wrote:
 On Mon, Apr 15, 2013 at 11:33 AM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
 You don't know which timezone the server is in? That's what it wants.

 No, I don't - this app runs in different locations all over the world.

I found some code at php.net that does this:

date_default_timezone_set(@date_default_timezone_get());
$deftz = date('T');

And that is working for me and giving me what I need.


 Larry Martell larry.mart...@gmail.com wrote:

 On Mon, Apr 15, 2013 at 11:17 AM, Jonathan Sundquist
 jsundqu...@gmail.com wrote:



 On Mon, Apr 15, 2013 at 12:14 PM, Larry Martell larry.mart...@gmail.com
 wrote:

 I have a client that has an app the runs with PHP 5.1.6. They want to
 upgrade to 5.3.3. First issue I ran into, they have a line of code
 that is:

 $deftz = date(T);

 I'm getting this for that line:

 [Mon Apr 15 10:44:16 2013] [error] [client 10.7.14.21] PHP Warning:
 date(): It is not safe to rely on the system's timezone settings. You
 are *required* to use
 the date.timezone setting or the
 date_default_timezone_set() function. In case you used any of those
 methods and you are still getting this warning, you most likely
 misspelled the timezone identifier. We selected 'America/Denver' for
 'MDT/-6.0/DST' instead in /home/www/itrade-dev/defs.inc on line 349

 So I changed it to

 $deftz = date.timezone;

 and now I get:

 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant date - assumed 'date' in
 /home/www/itrade-dev/defs.inc on line 349
 [Mon Apr 15 10:49:35 2013] [error] [client 10.7.14.21] PHP Notice:
 Use of undefined constant timezone - assumed 'timezone' in
 /home/www/itrade-dev/defs.inc on line 349

 Why is this undefined?


 You need to set the default time zone in this fashion,

 http://php.net/manual/en/function.date-default-timezone-set.php


 But I don't know the timezone - I'm trying to get it so I can convert
 times I get from the database to a user requested timezone.

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



Re: [PHP] timezone

2013-04-15 Thread Larry Martell
On Mon, Apr 15, 2013 at 1:59 PM, Lester Caine les...@lsces.co.uk wrote:
 Larry Martell wrote:

 No, I don't - this app runs in different locations all over the world.

 I found some code at php.net that does this:

 date_default_timezone_set(@date_default_timezone_get());
 $deftz = date('T');

 And that is working for me and giving me what I need.


 But do you ACTUALLY know what time zone is stored IN the database? What if
 te database was from another server?

 One of the 'standards' adopted when working world wide is to ensure what is
 stored IN the database is always UTC based. So you can always compare times
 on the same consistent base. The only time you need the offset is to display
 a local time, and that is either the time local to the server, or the time
 local to the client.

 The 'default' timezone is not necessarily the right one in either case ;)

I misspoke - the data in the db is in UTC. This is used to covert the
time of day on the server to the user's local timezone.

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



Re: [PHP] timezone

2013-04-15 Thread Larry Martell
On Mon, Apr 15, 2013 at 2:57 PM, Maciek Sokolewicz
maciek.sokolew...@gmail.com wrote:
 On 15-4-2013 22:12, Larry Martell wrote:

 On Mon, Apr 15, 2013 at 1:59 PM, Lester Caine les...@lsces.co.uk wrote:

 Larry Martell wrote:


 No, I don't - this app runs in different locations all over the world.


 I found some code at php.net that does this:

 date_default_timezone_set(@date_default_timezone_get());
 $deftz = date('T');

 And that is working for me and giving me what I need.



 But do you ACTUALLY know what time zone is stored IN the database? What
 if
 te database was from another server?

 One of the 'standards' adopted when working world wide is to ensure what
 is
 stored IN the database is always UTC based. So you can always compare
 times
 on the same consistent base. The only time you need the offset is to
 display
 a local time, and that is either the time local to the server, or the
 time
 local to the client.

 The 'default' timezone is not necessarily the right one in either case ;)


 I misspoke - the data in the db is in UTC. This is used to covert the
 time of day on the server to the user's local timezone.


 You are aware that the code you used is really bad practice, right? You're
 basically hiding the error no default timezone set by getting the default
 timezone, which returns an error; surpressing that error, providing the
 date_default_timezone_set function with the default value of
 date_default_timezone_get if none is defined (which there should!!), being
 UTC.

 So in short, you're saying set the default timezone to the default timezone
 if no timezone is set, which I know there is not. That's very hard to
 understand for future programmers reading your code. Why not just set
 date_default_timezone_set('UTC'). It's clear, resolves the warning and
 works perfectly, instead of relying on vague defaults somewhere, in the hope
 they're set right.

 On a sidenote; the reason why your original fix did not work:
 $deftz = date.timezone;
 Is because date.timezone is an ini setting. Not valid PHP code. And the
 error actually tells you you need to SET date.timezone, not set a variable
 TO the ini setting. In other words, you wanted date.timezone = UTC instead
 of $tz = date.timezone (which makes no sense anyway)

But UCT is not the timezone. When this app runs in New Mexico (where I
am) it's Mountain time. When it runs in NY it's Eastern. When it runs
in Tokyo it's JST, etc. The user has the option of setting the
timezone all times are displayed in. They can select any timezone
regardless of where they are. The app displays the last update time in
the user selected TZ. So I have to convert the time I get from the
server to that.

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



[PHP] Date weirdness

2013-03-28 Thread Larry Martell
I think I am losing my mind. I have some time zone converting code,
and I just don't understand what I am seeing. Also my system seems to
return the wrong time after I do some date operations on unrelated
objects.

This is from a machine that is in eastern time. I want to convert to,
for example central time:


$ndate = new Date(date(Y-m-d H:i:s));
echo $ndate-format(%Y-%m-%d %H:%M:%S);
2013-03-28 15:35:07  - this is the correct time

$ndate-setTZbyID(EDT);
echo $ndate-format(%Y-%m-%d %H:%M:%S);
2013-03-28 15:35:07 - still correct

$ndate-convertTZbyID(US/Central);
echo $ndate-format(%Y-%m-%d %H:%M:%S);
2013-03-28 10:35:07 - this is wrong it should be 14:35:07

$xdate = new Date(date(Y-m-d H:i:s));
echo $xdate-format(%Y-%m-%d %H:%M:%S);
2013-03-28 19:35:07 - HUH? This is wrong - should be 15:35:07

What in the world is going on here?

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



Re: [PHP] Date weirdness

2013-03-28 Thread Larry Martell
On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples sstap...@mnsi.net wrote:
 I think I am losing my mind. I have some time zone converting code, and I
 just don't understand what I am seeing. Also my system seems to return the
 wrong time after I do some date operations on unrelated objects.

 This is from a machine that is in eastern time. I want to convert to, for
 example central time:

 $ndate = new Date(date(Y-m-d H:i:s));
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07  - this is the correct time

 $ndate-setTZbyID(EDT);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07 - still correct

 $ndate-convertTZbyID(US/Central);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 10:35:07 - this is wrong it should be 14:35:07

 $xdate = new Date(date(Y-m-d H:i:s));
 echo $xdate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 19:35:07 - HUH? This is wrong - should be 15:35:07

 What in the world is going on here?


 I found this function a while back when I was converting UTC to EST... simple 
 task I know, but still...

 ( I am sorry to whomever wrote this, I didn't keep the source where I found 
 it )

 function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz = 
 'America/Toronto')
 {
 $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
 $time_object-setTimezone(new DateTimeZone($to_tz));
 return $time_object-format('Y-m-d H:i:s');
 }

I don't seem to have the DateTime object. We are running 5.1.6 and
that was added in 5.2.0. We are getting the Date module from an
external extension. I'll have to see about upgrading.

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



Re: [PHP] Date weirdness

2013-03-28 Thread Larry Martell
On Thu, Mar 28, 2013 at 4:55 PM, Maciek Sokolewicz
maciek.sokolew...@gmail.com wrote:
 On 28-3-2013 22:40, Larry Martell wrote:

 On Thu, Mar 28, 2013 at 2:44 PM, Steven Staples sstap...@mnsi.net wrote:

 I think I am losing my mind. I have some time zone converting code, and
 I
 just don't understand what I am seeing. Also my system seems to return
 the
 wrong time after I do some date operations on unrelated objects.

 This is from a machine that is in eastern time. I want to convert to,
 for
 example central time:

 $ndate = new Date(date(Y-m-d H:i:s));
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07  - this is the correct time

 $ndate-setTZbyID(EDT);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 15:35:07 - still correct

 $ndate-convertTZbyID(US/Central);
 echo $ndate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 10:35:07 - this is wrong it should be 14:35:07

 $xdate = new Date(date(Y-m-d H:i:s));
 echo $xdate-format(%Y-%m-%d %H:%M:%S);
 2013-03-28 19:35:07 - HUH? This is wrong - should be 15:35:07

 What in the world is going on here?


 I found this function a while back when I was converting UTC to EST...
 simple task I know, but still...

 ( I am sorry to whomever wrote this, I didn't keep the source where I
 found it )

 function convert_time_zone($date_time, $from_tz = 'UTC', $to_tz =
 'America/Toronto')
 {
  $time_object = new DateTime($date_time, new
 DateTimeZone($from_tz));
  $time_object-setTimezone(new DateTimeZone($to_tz));
  return $time_object-format('Y-m-d H:i:s');
 }


 I don't seem to have the DateTime object. We are running 5.1.6 and
 that was added in 5.2.0. We are getting the Date module from an
 external extension. I'll have to see about upgrading.

 Well, if you're getting the Date class from a custom extension, then we
 can't help you. Simply because we have no clue what the extension's code is.

 Also, please ask your host to upgrade, 5.1.6 is hopelessly outdated (and
 unsupported!). The current version is 5.4 with 5.5 coming out very very
 soon.


The extension is this:
http://pear.php.net/package/Date/docs/latest/Date/Date.html - but that
is also a very old version. I am working on getting the upgrade done.

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



[PHP] Re: [PHP-DEV] feature request : easy shared memory

2013-03-17 Thread Larry Garfield

On 03/14/2013 01:21 PM, Bob Weinand wrote:

Sharing active memory between processes goes against the shared nothing 
design of PHP.  The lack of the feature you're describing is itself a feature. :-)

If you had real shared memory, then you're now writing a multi-threaded app.  
Even if you aren't using threads per se it's the same level of potential for 
spooky action at a distance.  If your problem space really requires that (and 
there certainly are those that do), Java or NodeJs will suit you better because 
those are built specifically for a persistent-server model, rather than PHP's 
shared-nothing design. However, in practice most PHP/web applications don't 
need that, because HTTP is a stateless request/response system.  Shared-nothing 
more closely models what the actual environment is doing, and can still be very 
performant as long as you don't do anything naive.

If you're doing something stateful like Web Sockets, then you can run PHP as a 
cli application that is its own persistent server rather than as an Apache 
add-on.  For that, look at Ratchet: http://socketo.me/

--Larry Garfield

If PHP should be so restrictive against sharing, why are there extensions like 
memcached, ...? Someone must have missed this possibility to share rapidly...

If I need something like websockets, I use the pthreads extension: perfectly 
suited for stateful applications.

For example: I want to have the database in memory (no, no mysql Memory-tables; 
this is too slow...) and only do the updates into the database for faster 
access when most contents are read-only. What are these good reasons against 
such a feature except it violates the shares-nothing superlative of PHP. (Even 
if this feature would exist, you can still write PHP without sharing)

Bo Weinand


Memcache is out of process.  There are possible race conditions there, 
but FAR fewer and FAR more contained than true multi-threaded environments.


This list has debated the merits of shared-nothing many times before; it 
was a deliberate design decision in the interest of simplifying 
development for the overwhelming majority of users.  If your app is so 
performance sensitive that a memcache lookup is going to bring it to its 
knees, then either you're misusing PHP or you're better off using 
something other than PHP.  (PHP is not the tool for every use case.)


In any event, adding true shared memory to PHP would be nearly 
impossible without completely redesigning the way it interacts with web 
servers.  The alternative is to write your own PHP CLI application that 
connects to sockets itself and runs as a daemon (possibly using the 
pthreads extention as you mention), and cut apache/nginx out of the 
picture entirely.  If your use case calls for that, knock yourself out.  
But the good reasons against adding such a feature is that it would 
require rewriting everything and rearchitecting the entire Apache SAPI, 
which is not happening any time soon.


--Larry Garfield

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



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Larry Garfield

On 3/11/13 6:25 PM, Angela Barone wrote:

On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:

the variable $current_page does not exist.


That was my problem. :(  I've been staring at this for too long.  Too 
bad there's not a 'use strict' pragma.


There is.  Always set your development environment to E_ALL | E_STRICT, 
and it will yell at you about every little thing, including undefined 
variables.


http://php.net/manual/en/function.error-reporting.php


I would also suggest keeping with your original statement to return early and 
return often. Its best to exit out of your functions sooner than later.  
Specially if its a large function.


O.K.  I just thought there might be a more elegant way of doing it.  I 
at least got rid of the else statement like you mentioned.

Thanks for your help,
Angela


If you find yourself with a function that's too long and complex from 
the if-statements, your first step is to break it up into utility functions.


if (...) {
  // Something Long
}
else {
  // Something Else Long
}

Becomes:

if (...) {
  something_long();
}
else {
  something_else_long();
}

function something_long() {

}

function something_else_long() {

}

That helps both readability and testability.

Also, on your original boolean question, note that negation is 
distributive.  That is:


!($a  $b  $c)

is the same as:

!$a || !$b || $!c

Which means that if your checks are all equality checks, as in your 
case, you can simply do:


if ($a != 'a' || $b != 'b' || $c = 'c') {

}

Which may be easier to read.  If those checks are not trivial then 
there's also a micro-performance benefit there, as the first statement 
that evaluates to true will cause the whole thing to return true, so the 
second and third options don't need to be evaluated.


--Larry Garfield

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



Re: [PHP] static Logging class?

2013-03-03 Thread Larry Garfield
Make a real classed object that you pass to various objects that need 
it.  Otherwise you make your life way harder for unit testing.  Don't 
have a class that self-enforces that it's a singleton.  That way lies pain.


In particular, I recommend using or writing a class based on the PSR-3 
recommendation:


https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md

There's even stock code for the interface and some useful base classes 
available:


https://packagist.org/packages/psr/log

And for added fun, there are already publicly available open source 
libraries that implement PSR-3 that you can just drop in and use, such as:


https://packagist.org/packages/monolog/monolog

(If that's too heavy for you, writing your own PSR-3 compatible logger 
is dead-simple.)



I'm sure you're about to say zOMG this is just a hobby project, I don't 
need something that fancy and all injected and shit!  If it's a simple 
project, use a simple container to do all the hard work for you:


https://packagist.org/packages/pimple/pimple

(That's  100 lines of executable code.  Quite powerful, dead simple to 
use.)


Cheers.

--Larry Garfield, FIG member


On 03/03/2013 07:26 AM, Lars Nielsen wrote:

Hi,

I work on a little hobby-project, and i want to make a oo logging
facility. (php5.3 oop)

Is it best to make a class with static functions that i can call from my
other classes? Or is it more appropriate to make a real logging-class i
should instantiate every time i need to log something? (I just want to
log to a file)

Best regards
Lars Nielsen





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



Re: [PHP] Affordable low-fee e-commerce - DIY?

2013-02-18 Thread Larry Martell
On Mon, Feb 18, 2013 at 1:26 PM, George Langley george.lang...@shaw.ca wrote:
 Hi all. Am wanting to build a site where people can donate $1.00 but is not 
 for charity or other non-profit per se. So if I use PayPal, with their 2.9% + 
 .30 per transaction fee, that equals .33 cents for each dollar - that's a 
 full third of the amount the people would be giving. Credit cards appear to 
 be similar, with some percantage and about .22 cents per transactions.
 Am wondering what other options I'm missing, that won't take such a chunk out 
 of the low price? Is it easy enough to code to some other API for free (or at 
 least cheaper)?

Doesn't paypal only charge when someone pays with a credit card? If
they pay out of their bank account there is no charge to the
recipient.

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



Re: [PHP] Formatting -- defining sections of code

2012-12-14 Thread Larry Martell
On Fri, Dec 14, 2012 at 11:20 AM, Paul M Foster pa...@quillandmouse.com wrote:
 On Fri, Dec 14, 2012 at 10:48:05AM -0500, Andy McKenzie wrote:

 Hey folks, kind of a strange question here.

 Basically, I've been trying to move my style from self taught to Oh
 yeah, there IS a standard for this.  One of the things I frequently
 want to do is define sections of my code:  to take a simplistic
 example, this outputs everything that needs to be in file A, this
 outputs what needs to be in file B, and so on.

 Up until now, I've used my own standards (generally 
 SectionName, since it's easy to search for).  But it occurs to me to
 wonder;  IS there a standard for this?  Most likely, the programming
 world being what it is, there either isn't one or there are lots of
 competing standards, but I'd be interested to know...

 A *standard* for something? ROTFL! Yeah, like there's a standard for
 herding cats! [guffaw]

The nice thing about standards is that there are so many of them to choose from.
  -Andrew S. Tanenbaum

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



Re: [PHP] Lucene library

2012-12-13 Thread Larry Garfield

Ah ha.  Did that ever get ported to Zend 2?

--Larry Garfield

On 12/12/12 12:07 AM, Louis Huppenbauer wrote:

There's Zend_Search_Lucene, part of the Zend framework. I think it should
be possible to use it without the whole framework though.

http://framework.zend.com/manual/1.12/de/zend.search.lucene.html


2012/12/12 Larry Garfield la...@garfieldtech.com


Yes, I've worked with Apache Solr quite a bit.  It's a separate server,
however, and I'm looking for something with smaller requirements for a
concept I want to try. I'd consider SQLite, but I really need something
schema-free and PHP-native/easily-installable.

--Larry Garfield


On 12/11/2012 07:20 PM, israele...@gmail.com wrote:


Check out apache solr.

The php implementation of Lucene was very slow and had a lot of
perfomance issues the last time I tried it
--Original Message--
From: Larry Garfield
To: php-general@lists.php.net
Subject: [PHP] Lucene library
Sent: Dec 11, 2012 5:41 PM

Hi all.

I recall hearing about there being a PHP port of the Lucene library some
years ago, but I don't recall whence it came.  It was a stand-alone PHP
lib, which needed some integration to be viable as an actual search
engine but worked up to a point by storing data straight on disk as
files.  That meant it didn't scale beyond a few tens of thousands of
records, but that's still a decent number.

Does that ring a bell for anyone?  Anyone know if it still exists, and
if so where?  I didn't find it in https://packagist.org/ , which is
where I figured it would be if it were still maintained.

I may have a use for it if it still exists.

--Larry Garfield




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






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



[PHP] Lucene library

2012-12-11 Thread Larry Garfield

Hi all.

I recall hearing about there being a PHP port of the Lucene library some 
years ago, but I don't recall whence it came.  It was a stand-alone PHP 
lib, which needed some integration to be viable as an actual search 
engine but worked up to a point by storing data straight on disk as 
files.  That meant it didn't scale beyond a few tens of thousands of 
records, but that's still a decent number.


Does that ring a bell for anyone?  Anyone know if it still exists, and 
if so where?  I didn't find it in https://packagist.org/ , which is 
where I figured it would be if it were still maintained.


I may have a use for it if it still exists.

--Larry Garfield

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



Re: [PHP] Lucene library

2012-12-11 Thread Larry Garfield
Yes, I've worked with Apache Solr quite a bit.  It's a separate server, 
however, and I'm looking for something with smaller requirements for a 
concept I want to try. I'd consider SQLite, but I really need something 
schema-free and PHP-native/easily-installable.


--Larry Garfield

On 12/11/2012 07:20 PM, israele...@gmail.com wrote:

Check out apache solr.

The php implementation of Lucene was very slow and had a lot of perfomance 
issues the last time I tried it
--Original Message--
From: Larry Garfield
To: php-general@lists.php.net
Subject: [PHP] Lucene library
Sent: Dec 11, 2012 5:41 PM

Hi all.

I recall hearing about there being a PHP port of the Lucene library some
years ago, but I don't recall whence it came.  It was a stand-alone PHP
lib, which needed some integration to be viable as an actual search
engine but worked up to a point by storing data straight on disk as
files.  That meant it didn't scale beyond a few tens of thousands of
records, but that's still a decent number.

Does that ring a bell for anyone?  Anyone know if it still exists, and
if so where?  I didn't find it in https://packagist.org/ , which is
where I figured it would be if it were still maintained.

I may have a use for it if it still exists.

--Larry Garfield




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



Re: [PHP] Multithreading for OOP PHP

2012-10-31 Thread Larry Garfield

On 10/31/12 1:58 AM, Florian Müller wrote:

Hi guys
I was wondering, what actually the reason is that PHP itself does not support 
multi-threading?
I guess this would be realizable, or not? If not, why?
Maybe this is a stupid question, but still somehow interesting. Realization in 
a way as Java does (or just something in that way) would actually be a very 
nice thing, don't you think?
Thank you for your answers :)
Florian


PHP is by design a shared-nothing architecture.  What's happening in one 
process/request cannot impact what's in another request.  They may both 
write out to the same external service (DB, memcache, etc.), but they do 
not interact.  That makes the program much much simpler, since you don't 
need to worry about state synchronization.  It also means you can scale 
up by just adding more servers, because you don't need to deal with oh, 
now the memory isn't shared, so now what do I do?  Each PHP process 
could be in its own CPU core, CPU, server, or server cluster, and the 
code doesn't change in the slightest.


The shared nothing architecture is a very deliberate design decision, 
and is in a large part responsible for PHP's success.


--Larry Garfield

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



Re: [PHP] foreach

2012-10-17 Thread Larry Garfield

On 10/17/12 10:17 AM, Matijn Woudt wrote:

On Wed, Oct 17, 2012 at 1:25 AM, Larry Garfield la...@garfieldtech.com wrote:


For the love of god, please stop using ext/mysql (aka the mysql_*
functions).  It's insecure and slow and lacks features.

Instead, use PDO, and bind your parameters.  As a nice bonus, the result
from a PDO-based query is not a raw resource but an iteratable object, which
means you can foreach() it.

http://php.net/manual/en/book.pdo.php

$conn = new PDO(...);
$result = $conn-query(SELECT * FROM items);
foreach ($result as $record) {
   // Do something with each record here.
}

--Larry Garfield



Yes, the mysql extension is deprecated, but what's wrong with mysqli?
mysqli has the advantage that you don't need to keep a database handle
floating around, but you can just use mysqli_query everywhere.
When having multiple files and classes, it's terrible to pass $db to
each function/class, and I hate to use the global keyword.

just use while($record = $result-fetch_array()) instead of
foreach($result as $record)

And you mention ext/mysql is slow, well don't know about that, but PDO
is a bit slower than mysqli atleast.
I quote from [1]:
For inserts, there was no significant difference between MySQLi and
PDO (prepared statements or not). For selects, MySQLi was about 2.5%
faster for non-prepared statements and about 6.7% faster for prepared
statements. 

- Matijn

[1] http://jnrbsn.com/2010/06/mysqli-vs-pdo-benchmarks


Nothing is wrong with mysqli per se.  It's up to date and secure, and 
certainly better than ext/mysql.  I recommend PDO over mysqli because:


1) PHP-engine-level global state (ie, not specifying a connection) is 
the source of most (although not quite all) evil.  Really, that way lies 
pain once you get into anything reasonably complicated and want to be 
able to test it properly.


2) PDO is installed by default on virtually every PHP system in the 
world.  ext/mysqli has never been part of the default build of PHP, and 
many to most web hosts don't have it installed.


3) mysqli's API is a bizarre hybrid of procedural and OO that confuses 
the heck out of me.  PDO's is far from perfect, but is more consistent 
and cleanly OO from the get-go.


I skipped mysqli entirely and went straight to PDO when it became available.

--Larry Garfield

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



Re: [PHP] foreach

2012-10-16 Thread Larry Garfield

On 10/15/12 9:05 PM, David McGlone wrote:

On Monday, October 15, 2012 08:21:23 PM you wrote:

Bastien Koert

On 2012-10-15, at 8:16 PM, David McGlone da...@dmcentral.net wrote:

I've been sitting here playing around with foreach() and I'm wondering why
I am getting these results. here's what I've been fooling around with.
the code has no perticular meaning, but I noticed if the script fails, I
get the sentence Too expensive I'm going home LOL 6 times because there
are 6 words in the sentence. I also have a database that looks like this:

product_idproductprice
1Milk2.59
2bread1.05

And when $row is equal to 0 the output I get is
1 1 Milk Milk 2.59 2.59 Which is printed to the screen according to how
many rows are in the db I belive.

So my question is why this behavior? I was expecting something like a
while
loop.


Dave,

Foreach is an iterator over an array. Your $row is a pointer to a db result
set. If you were to pass the $row result set to the foreach as an array,
you'd get what you think you should

Www.php.net/foreach


Thanks Bastien.
Heres what I started with:

$result = mysql_query(SELECT * FROM items);
$row = mysql_fetch_array($result);
foreach($row as $rows){
$row = 0;
if($row == 0){
echo $rows;
} else{
echo Too expensive I'm going home LOL;
}
}

Here's what I ended up with after you gave me the advise:
$result = mysql_query(SELECT * FROM items);
   $rows = array();
   while($row = mysql_fetch_array($result))
$rows[] = $row;
   foreach($rows as $row){
   $product = $row['product'];
   $price = $row['price'];
 echo $product ;
 echo $price ;


 $justright = 0;
 $toohigh = 5; //I was going to use this to check if the price was too high
just so I could use an elseif in the exercise, 
but I realized that
it would only work if the if() evaluated to 
false, which would be   
impossible. Ahhh pizz on it, it was fun anyway! 
:-)

 if($justright = $price){
  echo Not bad. I'll buy it.br /;
   } else
  echo Too expensive I'm going home LOL ;

   }


For the love of god, please stop using ext/mysql (aka the mysql_* 
functions).  It's insecure and slow and lacks features.


Instead, use PDO, and bind your parameters.  As a nice bonus, the result 
from a PDO-based query is not a raw resource but an iteratable object, 
which means you can foreach() it.


http://php.net/manual/en/book.pdo.php

$conn = new PDO(...);
$result = $conn-query(SELECT * FROM items);
foreach ($result as $record) {
  // Do something with each record here.
}

--Larry Garfield

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



Re: [PHP] The end of mysql

2012-09-09 Thread Larry Garfield
Then get a new host.  A host that disables PDO these days is a host that 
deserves to go bankrupt. ext/mysql has been dead for years now.


--Larry Garfield

On 09/08/2012 08:54 AM, Jim Giner wrote:

Nope. No PDO as yet either

jg


On Sep 7, 2012, at 11:22 PM, Adam Richardson simples...@gmail.com wrote:


On Fri, Sep 7, 2012 at 9:58 PM, Jim Giner jim.gi...@albanyhandball.com wrote:

So with the announced end of the mysql functions (and switching to a
different extension), one would think that my isp/hoster would be a bit more
interested in my dilemma.  I tried today to create my first mysqli-based
test script and found that I didn't have that extension.  A series of emails
with my tech support told me that the shared server farm does not get
mysqli - only their business servers.  Since I dont' have a need for and
want to pay more for a 'business server', I'm told I'm s... outta luck.

What about PDO? Is that available?

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

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





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



Re: [PHP] The end of mysql

2012-09-09 Thread Larry Garfield
And I didn't see the follow-up messages saying that they do support PDO 
after all.  Crisis averted! :-)


I have actually found very few hosts that run ext/mysqli. Everyone I 
know jumped from ext/mysql to PDO.  I've never actually run mysqli 
myself; at this point everything I do is PDO.


--Larry Garfield

On 09/09/2012 04:49 PM, Larry Garfield wrote:
Then get a new host.  A host that disables PDO these days is a host 
that deserves to go bankrupt. ext/mysql has been dead for years now.


--Larry Garfield

On 09/08/2012 08:54 AM, Jim Giner wrote:

Nope. No PDO as yet either

jg



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



Re: [PHP] OT (maybe not): Drupal vs WordPress

2012-08-28 Thread Larry Garfield

Only semi-joking line that's been making the rounds lately:

If you want to build a blog, use Wordpress.
If you want to build Wordpress, use Drupal.
If you want to build Drupal, use Symfony2.

There is much wisdom in those lines.

--Larry Garfield, an openly biased Drupal core developer

On 8/19/12 2:52 PM, l...@afan.net wrote:

Hi to everyone,
I was trying to figure this out for the last week or two. I have read tons
of articles that compare Drupal and WordPress, but I still wasn't swayed
to either side.
I know that they are both good, both do the job well, and both have
advantages and disadvantages. For example, Drupal has a steeper learning
curve, but you get more control over the website.
Most of Drupal vs WordPress articles are emotionally driven and it
reminds me of the PC vs Apple flame war. I was trying to exclude these as
much as I could but it's hard.

Is there any website/article/benchmark/test/experiment/whatever I can
trust to be unbiased? I need a website that measures the CMS' through
facts, not heated, emotional arguments. In which cases is it better to use
Drupal over WordPress (and vice-versa)? I know the first two words are
going to be it depends, but let's talk about it in general (for small
basic websites, more complex websites, easy customization, etc).

I found this on one page: ... Drupal was built as a fine-grained
multi-role system where you can assign different permissions to different
roles to do different things (e.g. content editor, content reviewer,
member, etc.) and assign users to these roles... Does that mean that
WordPress can't do that? Maybe it can, and the quotation is true, but it
is kind of misleading to say that one of the programs does something, and
then not mention the other product at all.

Special points for me are (not a must, though)
- multiple websites with single core (both CMSs have the capability but I
got impression Drupal does it better?) because of maintenance
- compatibility with CiviCRM

Once I decide what to use, I have to stick with it for a while.

Thanks for any help.

LAMP




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



Re: [PHP] OT (maybe not): Drupal vs WordPress

2012-08-28 Thread Larry Garfield

On 8/20/12 3:36 AM, Simon Schick wrote:


One thing I also really like at the TYPO3-philolsophy: If someone
finds a security-issue he should immediately get in contact with the
developers (of the extension and the TYPO3 security team) and discuss
the issue with them. They decide how critical the bug is and will do a
hard work to get the fix as soon as possible. If it is a very critical
issue (someone could gain admin-access by something) they will send
out an email that there will be a bugfix coming out at next-coming day
at 9 o'clock GMT and everyone is advised to update his TYPO3-core or
the extension. This is something I really like! To be prepared for
some critical fix and knowing that (in a perfect case) no-one should
have heard about that issue before who wants to hack my website :)

Don't know if there's some similar security-policy in other
communities than this :)


Drupal's security process is substantially similar, and also follows 
security best practices:


http://drupal.org/security-team

--Larry Garfield

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Larry Garfield

On 8/27/12 4:09 PM, Mark wrote:

On Mon, Aug 27, 2012 at 4:26 PM, Stuart Dallas stu...@3ft9.com wrote:



2. Let the plugin itself (so in this case PluginOne.php) open itself
and register it to the PluginLoader.

With the first option i have to do eval which i try to avoid if possible.
With the second solution the PluginLoader probably has to be a singlethon.


Why does it need to be a singleton?


Well, i would then do something like this from within the included
plugin file after the class:
PluginLoader::getInstance()-registerPlugin(new PluginOne());

Or something alike.


I'm not sure I see what PluginLoader is doing? It makes more sense to me if you 
register like so:

PluginLoader::getInstance()-registerPlugin('PluginOne');

Then you get an instance of the plugin:

$plugin = PluginLoader::getInstance()-factory('PluginOne');

Tho, even then I don't see what the PluginLoader is adding to the party.


Well, i'm making the classes up as i type. I don't actually have a
PluginLoader yet. Or rather, i'm just beginning to make it right now.
What it's doing is very simple. Read through the directory of the
plugins and load every single plugin it finds in memory. Then every
plugin registers the mime types it can handle. That information is
stored in the PluginLoader upon which some other place can call:
PluginLoader::pluginForMime(text/html). Though i still have to take
a good look at that.

But you're right, i can use the factory pattern here.



Ahh, I see. Personally I'd go with the following (pseudocode)...

Inside the PluginLoader constructor (or other method)
   foreach (plugindir)
 require plugindir/plugindir.php
 $plugindir::init($this)

The static init() method calls PluginLoader::registerPlugin('mime/type', 
'PluginClassName'). Then pluginForMime does a lookup for the mime type and 
returns an object of the corresponding type. That way a single plugin can 
support multiple mime types.

-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


That sounds sane and i probably go for that :)
Thanks for clarifying it a little.


You should never be calling require() yourself.  Just follow the PSR-0 
naming standard and use an autoloader, then you don't have to even think 
about it.  There are many existing autoloaders you can use, including 
Composer's, Symfony2's, and probably Zend has one as well.


Also, the key question is how you'll be mapping your situation to the 
plugin you need.  If it's fairly hard-coded (i.e., mime type of foo = 
class Bar), then just use a simple dependency injection container like 
Pimple.  If it's more complex and situational, then yes a factory is the 
easiest approach.


--Larry Garfield

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



Re: [PHP] What's the best way to make a dynamic plugin architecture?

2012-08-27 Thread Larry Garfield

On 8/27/12 6:11 PM, Matijn Woudt wrote:


You should never be calling require() yourself.  Just follow the PSR-0
naming standard and use an autoloader, then you don't have to even think
about it.  There are many existing autoloaders you can use, including
Composer's, Symfony2's, and probably Zend has one as well.



I believe there's one in PHP by default now called SPLClassLoader or
something like that..

- Matijn


There was a proposal for one, but it was never added.  You still need a 
user-space class loader for PSR-0, but they're readily available.


--Larry Garfield

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



Re: [PHP] Re: [PHP-WEBMASTER] Re: [PHP] The Cat Signal

2012-07-23 Thread Larry Garfield
Sales tax isn't the point with SOPA/PIPA.  Thinks like the government 
being able to force any site off the Internet at the ISP / DNS level on 
the say-so of a private corporation are the point.  And no, that's not a 
defensible or acceptable position.  Breaking the Internet to prop up 
industries that don't like being disrupted is not a proper use of 
governmental power.


I'm quite happy to see PHP.net joining in with other defense-of-freedom 
voices.


--Larry Garfield

On 7/21/12 1:56 PM, With No Name wrote:

On Fri, July 20, 2012 10:04, Lester Caine wrote:

In Europe VAT is applied even on on-line sales. It is the likes of Amazon
  shipping bulk stock from overseas 'clients' into European warehouses and
then supplying them without VAT added directly in Europe that is the
problem! How can I compete with someone who is also giving next day
delivery, but 20% cheaper ... American sellers are one of the problems
here.


It depends, because in Europe (I live in Germany), VAT is only added if
the value + shiping exceeds 25 Euro and customs are only added, if the
value exceeds 150 Euro

It does NOT discriminate American sellers, because German sellers have to
bill the VAT too

Also I buy regulary in the USA and even with heavy USPS costs plus Import-VAT
I am mostly lesser expensive as if I buy in Germany...

Greetings



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



Re: [PHP] Re: php batch/queue framwork

2012-06-30 Thread Larry Garfield

On 06/29/2012 05:18 AM, Tom Sparks wrote:

Forwarded Message: php-general_318334.ezm
Re: php batch/queue framwork
Friday, 29 June, 2012 6:30 AM
From:
Shailesh N. Humbad humb...@alum.mit.edu
To:
php-general@lists.php.net
On 6/28/2012 11:58 AM, Tom Sparks wrote:
I am looking for a batch/queue framework that is database-centric?
I could write my own, but I want one that is mature

tom_a_sparks
It's a nerdy thing I like to do


You could try Amazon Simple Queue Service: http://aws.amazon.com/sqs/
Use the PHP SDK: http://aws.amazon.com/sdkforphp/

I was hoping for something that I could run local on my host

tom


Have a look at Beanstalk and Gearman.  They're the most common 
run-yourself queues I've seen, and both have PHP libraries available.


ZeroMQ is also the darling of the queuing world these days, but I don't 
know off hand how good the PHP support is.


You won't find a GOOD database-centric queue framework, rather by 
definition.  A queuing server may use a DB of some kind as a backend 
itself, but a queue server by definition pushes tasks to workers that 
are waiting for it.  That's simply not how an SQL DB is designed.  You 
would have to do a polling worker that polls a database for new tasks.  
You could write such a system -- Drupal comes with one as a default 
implementation since then you don't need a separate queueing program, 
for instance -- but it will always be greatly inferior to a real 
daemonized queue server.


--Larry Garfield

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



Re: [PHP] What's happened to our newsgroup?

2012-06-26 Thread Larry Martell
On Tue, Jun 26, 2012 at 1:30 PM, TR Shaw ts...@oitc.com wrote:

 On Jun 26, 2012, at 3:28 PM, Steven Staples wrote:


 -Original Message-
 From: Govinda [mailto:govinda.webdnat...@gmail.com]
 Sent: June 26, 2012 3:25 PM
 To: PHP-General List
 Subject: Re: [PHP] What's happened to our newsgroup?


 No postings for days.

 everyone RTFM?
 :-)



 Maybe they joined the British mailing list?


 Maybe its just the summer.

Maybe they're working in Django now (like I am).

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



Re: [PHP] code deployment through php

2012-05-01 Thread Larry Garfield

On 5/1/12 4:19 AM, rene7705 wrote:

On Tue, May 1, 2012 at 11:11 AM, Camilo Sperbergunrea...@gmail.com  wrote:


If I understood the problem correctly, you want to keep a single copy of
your code on every machine you work, including the final server.



Well, I want to work on 1 copy of my common code on my windows machine,
then sync those changes to all my sites (hosted on the win dev box) to see
if it messes up the other sites, then FTP those changes to my hosting
account, and run the sync script there as well.



Have you read about SVN ? You can set up a cronjob to execute it
automatically if you want, there are clients for Windows, Zend Studio, etc
etc.



I've read about some source control systems, I've tried them out, but I'd
rather go for this simpler approach tbh.
I already do regular backups that are timestamped, it's enough for me right
now I think.


No it's not.  Really.  For what you describe, a proper version control 
system is the correct tool.  Rolling your own with rsync and cron is 
setting yourself up for failure.


A couple people here have mentioned SVN.  I used to use SVN, but now 
have migrated everything I do to Git.  Without getting into a religious 
battle between Git and SVN, I do strongly recommend you look into it. 
This is an excellent resource for why to use it and how to use it:


http://progit.org/book

If you're serious about development, get serious about version control.

--Larry Garfield

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



Re: [PHP] To ? or not to ?

2012-04-05 Thread Larry Garfield

On 4/4/12 12:14 AM, Donovan Brooke wrote:

Robert Cummings wrote:
[snip]

Could using ob_start and ob_end_flush eliminate the ambiguity of whether
or not to use '?'?


In the generally recommended case of don't use them at the end of your
file... where's the ambiguity?



http://www.php.net/manual/en/function.include.php

http://www.php.net/manual/en/language.basic-syntax.phpmode.php

Those seem to suggest to use them... thus the ambiguity.


Donovan


Most major projects at this point leave it off, and their coding 
standards say to as well.  The official PHP docs are generally 
non-commital by design, but outside of those I think it's pretty 
well-established to just leave it off and be happy.


--Larry Garfield

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



[PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
Hello, when I pass a variable whose value originally came from $_GET
or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
string. Note that the file is successfully opened and written to by
the script, but the variable that originally came from $_GET does not
have its value interpolated in the text file, even though it does get
interpolated in the echo().

 Code 
?
$meh = $_GET[q];
$writeline = : . $meh . : . strlen($meh) . PHP_EOL;
echo ( $writeline );

$fp = fopen(/tmp/wtf.log,w+);
fwrite($fp, $writeline );
fclose($fp);

var_dump($writeline);
?

 Request 

/search.php?q=meh123

 Response --- ( expected )

:meh123:6 string(10) :meh123:6 

 Contents of /tmp/wtf.log 
::0

Some sort of security setting in php.ini maybe? If so, I'm not only
curious in how to fix it but also how this actually happens. Does the
value assigned to $writeline not get immediately evaluated? I mean,
does $writeline know it contains variables from elsewhere, instead
of just containing a string of chars?

Thanks!

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



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

I have removed the wtf.log file between runs, just did it once more.
Same thing happens. A new file is created, and the contents are ::0

So I'm sure its not a permissions issue ( However I'm also sure that
this shouldn't be happening so... ) Thanks.

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



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

Yes I have tried to set a variable explicitly with a string, and that
variable does end up interpolated into the file. I just tried using
file_put_contents with the same result.

Here is a modified version, showing another variable that does work,
and file_put_contents():

?
$meh = $_GET[q];
$good = Yay I go in the File . PHP_EOL;
$writeline = : . $meh . : . strlen($meh) . : . $good;
echo ( $writeline );
file_put_contents(/tmp/wtf.log, $writeline );
var_dump($writeline);
?

Here the response/stdout:
:meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

But the file is the same:
root@prime:/tmp# rm wtf.log
root@prime:/tmp# ls wtf.log
ls: cannot access wtf.log: No such file or directory
[ I make the request ]
root@prime:/tmp# cat wtf.log
::0:Yay I go in the File

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



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

 Have you checked apache log files for any warnings/errors?
 How about writing $_GET['q'] directly? eg.
 file_put_contents('/tmp/wtf.log', $_GET['q']);?

Yes I tried using $_GET['q'] directly to no avail. However, you found
a clue! apache error.log is giving this:
PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2

Strange b/c I am obtaining and using that value successfully in echo()!

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



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 4:03 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 8:41 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

 Have you checked apache log files for any warnings/errors?
 How about writing $_GET['q'] directly? eg.
 file_put_contents('/tmp/wtf.log', $_GET['q']);?

 Yes I tried using $_GET['q'] directly to no avail. However, you found
 a clue! apache error.log is giving this:
 PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2

 Strange b/c I am obtaining and using that value successfully in echo()!

 Well.. That seems pretty buggy, I guess it's a bug in PHP. Try
 changing q in something else, and maybe you want to submit a bug
 report to PHP?

Changing the index name didn't help. I think I will submit a bug,
after a bit more scrutiny of my php.ini to make sure there isn't some
restriction in there. This is a default ubuntu apache/php.ini though.
Thanks again.

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



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Larry Garfield

On 2/7/12 1:50 PM, Micky Hulse wrote:

Was there ever a time when having a comma at the end of the last array
element was not acceptable in PHP?

I just did a few quick tests:

https://gist.github.com/1761490

... and it looks like having that comma ain't no big deal.

I can't believe that I always thought that having the trailing comma
was a no-no in PHP (maybe I picked that up from my C++ classes in
college? I just don't remember where I picked up this (bad) habit).

I would prefer to have the trailing comma... I just can't believe I
have avoided using it for all these years.

Thanks!
Micky


Drupal's coding standards encourage the extra trailing comma on 
multi-line arrays, for all the readability and editability benefits that 
others have mentioned.  We have for years.  Cool stuff. :-)


--Larry Garfield

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



Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Larry Martell
On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams a...@phcomp.co.uk wrote:
 On Mon, Feb 06, 2012 at 11:12:53AM -0500, Jim Giner wrote:
 NO GO!
 As one who started back in the 70's with old style coding that utilized GoTo
 in Cobol, Fortran, etc. and had to deal with spaghetti code written by
 even earlier developers who never considered that someone else would have to
 maintain their code, I feel strongly that GoTo is not to be used.

 I remember being faced with spaghetti code 35 odd years ago - yes, horrible.
 But what do we mean by ''spaghetti code'' ? I remember code where every 3rd
 statement was some form of GOTO - yuck!

 One very desirable feature of code is that it be clear, ie: lucid, able to be
 understood by others. Too many GOTO statements and it is hard.

 However: a few GOTOs can make things clearer.  Think of a function that can 
 fail
 in several different places (eg data validation, ...).  But it is reading a 
 file
 which needs to be closed before the function returns.  I have seen code where
 some $IsError variable is tested in many places to see if things should be 
 done.
 That is just as bad as lots of GOTO -- often when having to write something 
 like
 that I will have a GOTO (in several places) to the bottom of the function that
 closes the file and returns failure.

 That is much clearer than extra variables.

 If I survey my code I find that I use one GOTO in about 4,000 lines of code -
 that I do not find excessive.

 There are, however, people who consider any GOTO as communion with the devil.
 IMHO: not so - if used sparingly.

Just for another data point, the FAA does not allow gotos in any code
that goes into an airplane.

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



Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Larry Martell
On Mon, Feb 6, 2012 at 9:50 AM, Adam Richardson simples...@gmail.com wrote:
 On Mon, Feb 6, 2012 at 11:28 AM, Larry Martell
 la...@software-horizons.comwrote:

 On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams a...@phcomp.co.uk wrote:
  On Mon, Feb 06, 2012 at 11:12:53AM -0500, Jim Giner wrote:
  NO GO!
  As one who started back in the 70's with old style coding that utilized
 GoTo
  in Cobol, Fortran, etc. and had to deal with spaghetti code written by
  even earlier developers who never considered that someone else would
 have to
  maintain their code, I feel strongly that GoTo is not to be used.
 
  I remember being faced with spaghetti code 35 odd years ago - yes,
 horrible.
  But what do we mean by ''spaghetti code'' ? I remember code where every
 3rd
  statement was some form of GOTO - yuck!
 
  One very desirable feature of code is that it be clear, ie: lucid, able
 to be
  understood by others. Too many GOTO statements and it is hard.
 
  However: a few GOTOs can make things clearer.  Think of a function that
 can fail
  in several different places (eg data validation, ...).  But it is
 reading a file
  which needs to be closed before the function returns.  I have seen code
 where
  some $IsError variable is tested in many places to see if things should
 be done.
  That is just as bad as lots of GOTO -- often when having to write
 something like
  that I will have a GOTO (in several places) to the bottom of the
 function that
  closes the file and returns failure.
 
  That is much clearer than extra variables.
 
  If I survey my code I find that I use one GOTO in about 4,000 lines of
 code -
  that I do not find excessive.
 
  There are, however, people who consider any GOTO as communion with the
 devil.
  IMHO: not so - if used sparingly.

 Just for another data point, the FAA does not allow gotos in any code
 that goes into an airplane.

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


 Can I have the source for this so I can read the rationale? I'm curious
 which language implementation it's referencing (C, Ada, etc.) and what
 restrictions the language places on the construct. Again, the PHP version
 of the construct is beneficially quite restrictive. For instance, some
 people don't like giving programmers access to pointers just because you
 can get into so much trouble with them, but I wonder if they'd be concerned
 about Go's pointers, which don't allow pointer arithmetic, limiting one are
 of potential trouble:

 http://golang.org/doc/go_for_cpp_programmers.html#Conceptual_Differences

 Interesting.

The source is my own personal experience working for an avionics
company and working with the FAA to get our code certified under the
DO-178B standard. I never saw anything that said 'no GOTOs' but that's
what I was told. I was also told no C++ was allowed nor was any
recursion. This was important to me, as we had purchased some code
that was all that (C++, with recursion and GOTOs) and I was given the
task of rewriting it in C and removing the gotos and the recursion.

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



Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Larry Martell
On Mon, Feb 6, 2012 at 10:13 AM, Adam Richardson simples...@gmail.com wrote:
 On Mon, Feb 6, 2012 at 12:09 PM, Larry Martell
 la...@software-horizons.comwrote:


 The source is my own personal experience working for an avionics
 company and working with the FAA to get our code certified under the
 DO-178B standard. I never saw anything that said 'no GOTOs' but that's
 what I was told. I was also told no C++ was allowed nor was any
 recursion. This was important to me, as we had purchased some code
 that was all that (C++, with recursion and GOTOs) and I was given the
 task of rewriting it in C and removing the gotos and the recursion.


 Now that was probably a lot of work! Interesting that C++ was not allowed.

 Thanks for the background information,

I was a lot of work, but I was a contractor getting paid by the hour ;-);

I just pulled out my notes from that job - it took me 59 hours to do
the conversion and remove the gotos and recursion, and another 67
hours for testing, verification, integration, documentation, and
certification.

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



Re: [PHP] Re: Long Live GOTO

2012-02-06 Thread Larry Martell
On Mon, Feb 6, 2012 at 11:07 AM, Daniel Brown danbr...@php.net wrote:
 On Mon, Feb 6, 2012 at 12:59, Larry Martell la...@software-horizons.com 
 wrote:

 I just pulled out my notes from that job - it took me 59 hours to do
 the conversion and remove the gotos and recursion, and another 67
 hours for testing, verification, integration, documentation, and
 certification.

    And, having contracted with the federal government quite a bit
 myself, 180 days for implementation, followed by 25 years of
 upgrade-less utilization, then three years of deprecation and
 near-replication, ending with an abandoned, government-grade,
 bug-infested duplication, at the low-low cost of just $230 Million to
 the nation.

This was a job for a private company, and my code is in many aircraft
flying in the sky right now.

But I once did do a job for a company that was under contract to one
of the branches of the military, and we did spend $100s of millions of
the tax payers money to build a really cool inertial reference unit -
unfortunately, we only built one, and then they didn't want it any
more. I think I produced more power point slides then I did lines of
code :-(

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



Re: [PHP] news and article posts in one table

2011-11-27 Thread Larry Garfield

On 11/26/2011 09:45 PM, Paul M Foster wrote:

On Sat, Nov 26, 2011 at 01:26:49PM -0600, Tamara Temple wrote:


muad shibanimuad.shib...@gmail.com  wrote:


i wanna to create one table that contains both news and articles posts,
they have similar columns like id, title, content, and date but they are
differ in one column = the source of news or article post
article has  writers that have permanent names and pictures obtained from
another table called writers that supposed to be  left joined with the news
table, while news posts simply have a source as text like AFP
or Reuters and so one.

How I can solve this ?


How you store things in tables can sometimes get a little tricky. One
way to approach this is with normalized tables and using joins in your
query like you are doing. To make this work, in your main entries table,
have a field that indicates what the entry type is. If you are doing one
select that gets both articles and news stories, having that extra field
can help you distinguish what type it is, and which fields contain data
in each record.

(cf: Wordpress wp_posts table for an example of how this is done. They
store posts, pages, and attachments in a single table this way. I can't
say if this is a better arrangement than keeping them in separate
tables.)


I've had to hack this table. It's a prime example of bad design. Take a
long look at the records of this table in an active blog, with a survey
of each of the fields and their values. You'll see what I mean.

Paul


The Drupal approach to this problem is to have a common table for all 
nodes (our generic content object thingie), and then dependent tables 
for type-specific stuff.  So (over-simplifying):


node: id, title, type, created time, updated time, published (1 or 0)
field_body: node_id, delta, value
field_picture: node_id, delta, url
field_source: node_id, delta, url to reuters or whatever
field_writers: node_id, delta, writer name, url to writer picture
// etc.

That way, you can have the basic information all in one table and then 
specific fields can be shared by some, all, or just one node type, and 
all can be multi-value.  It does mean loading up a full object is 
multiple queries, but really, MySQL is fast.  You don't need to 
over-optimize your query count, and this gets you a well-normalized 
database.


If you know in advance exactly what your types are going to be (in 
Drupal they're user-configurable), you could simplify it to something like:


node: id, title, type, body. created time, updated time, published (1 or 0)
node_article: node_id, writer name, writer picture url
node_news: node_id, url to reuters or whatever

And you can still select on whatever you need.  With a LEFT JOIN, you 
can even get back all data on all articles of both types, and just have 
lost of nulls in the result set for the off-record fields.


--Larry Garfield

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



[PHP] PHP exercises

2011-11-25 Thread Larry Garfield
Hi folks.  A friend of mine is trying to learn PHP.  She already knows 
programming basics, but wants to learn PHP specifically.  However, she 
learns much better with assignments or exercises than just from reading 
articles or books.


The only site I've found so far is PHP Exercises 
(http://phpexercises.com/), but it of course went offline the day after 
I found it.  Fail!


Can anyone recommend other sources for tutorial-based or exercise-based 
PHP learning?  Paid is OK if it's not too expensive and it's worth the 
money, although free is always preferred.


TIA and all that.

--Larry Garfield

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



Re: [PHP] Headers already sent

2011-11-10 Thread Larry Garfield
Perhaps your server is configured to have output buffering enabled by 
default?  Check php.ini / phpinfo().


--Larry Garfield

On 11/11/2011 12:12 AM, Kranthi Krishna wrote:

Hi all,

I am missing something pretty obvious here. The PHP Manual says
Remember that header() must be called before any actual output is
sent, either by normal HTML tags, blank lines in a file, or from
PHP.. A simple test case shows otherwise

I have the following code

test
?php
setcookie(TestCookie, 'test');

nothing more nothing less.. only this code in a file

I get the output in the browser (test) AND the cookie is set
(verified by live HTTP headers). Any ides on why this is happening ?

Linux localhost 2.6.40-4.fc15.i686 #1 SMP Fri Jul 29 18:54:39 UTC 2011 i686
Apache 2.0 Handler
Zend Engine v2.3.0,  Xdebug v2.1.2
PHP 5.3.6

Kranthi.
http://goo.gl/e6t3



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



Re: [PHP] Friday Distraction

2011-10-21 Thread Larry Martell
On Fri, Oct 21, 2011 at 11:38 AM, Tedd Sperling tedd.sperl...@gmail.com wrote:
 On Oct 21, 2011, at 12:27 PM, Daniel Brown wrote:

    I'll get this week's Friday distraction kicked off here with
 something shared with me by a Facebook friend.  If you're on Facebook,
 try this.  It's pretty sweet (and safe for work and kids).

        http://www.takethislollipop.com/

 --
 /Daniel P. Brown

 Not meaning to be ignorant, but why?

 What's the point here?

 I have grandkids and about a dozen other species of relatives/friends trying 
 to get me to do stuff (i.e., like/friend/post/reply/accept) on FaceBook et 
 al, but I don't see the point. It looks like a total waste of time. Why 
 should I care if someone post something on their FaceBook account? I would 
 rather spend my time programming, teaching programming, and reading about 
 programming.

 Maybe I'm just getting too old for this stuff.

I couldn't agree more. It is a total waste of time, and for many
people they think it replaces the need for personal contact. Like you,
I have 100's of things I'd rather spend my time on.

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



Re: [PHP] Re: Repetitive answers . . .

2011-09-09 Thread Larry Martell
On Fri, Sep 9, 2011 at 12:36 PM, Daniel Brown danbr...@php.net wrote:
 On Fri, Sep 9, 2011 at 14:30, Robert Cummings rob...@interjinn.com wrote:

 Oblig: http://www.youtube.com/watch?v=sUntx0pe_qI

    I didn't know it was possible to fill almost four minutes with a
 single note, outside of a test pattern.  That's got to be the worst
 singer I've ever heard in my entire life.

I agree, I only lasted 1 minute.

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



[PHP] Books on PHP guts

2011-08-30 Thread Larry Garfield
Hi folks.  I'm not looking to write new PHP extensions per se, but am 
looking to better grok the guts of PHP itself.  (That's a first step on 
the way to writing new extensions, though.  Gateway drug!)  I'm 
especially interested in the memory/performance implications of various 
techniques.


Are there any good books on the subject that would be of help?  I'm 
familiar with Sara Goleman's book[1], which has generally good reviews, 
but it's several years old now and I'm not sure if there's anything 
newer that covers PHP developments since the 5.0 days.


Any suggestions?

--Larry Garfield

[1] 
http://www.barnesandnoble.com/w/extending-and-embedding-php-sara-golemon/1006978211


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



Re: [PHP] phpsadness

2011-06-03 Thread Larry Martell
On Fri, Jun 3, 2011 at 9:29 AM, Daniel Brown danbr...@php.net wrote:
 On Thu, Jun 2, 2011 at 22:14, Paul M Foster pa...@quillandmouse.com wrote:
 On Thu, Jun 02, 2011 at 01:02:26PM -0400, Daniel Brown wrote:

 On Tue, May 31, 2011 at 22:13, Bill Guion bgu...@comcast.net wrote:
 
  So if I understand, you want an explode() with empty parameters to explode
  the host machine?

     That's correct.  If it causes too much userland confusion, we can
 alias it as detonate() as well.

 It would be so hilarious if this made it into the docs as a (spoof)
 command. I could see some n00b skimming over the docs and going, Wait,
 what--?

 Oh-- how about if the detonate() command just echoed a series of tick
 strings to the web page? Can't you just imagine the frantic tech support
 calls from n00b PHP coders to the tech support departments of their
 hosting companies? Oh crap oh crap! Pick up the phone already! Oh
 crap I'm so busted!

 Reminds me (obliquely) of an entry in the index for The C Programming
 Language for recursion, which points right back to that index page. I
 about doubled over when I first discovered it.

    That's hilarious.  I love subtle humor like that.

Check out intercal:

http://en.wikipedia.org/wiki/INTERCAL

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



Re: [PHP] iPhone sadness

2011-05-30 Thread Larry Martell
On Mon, May 30, 2011 at 9:35 AM, Andre Polykanine an...@oire.org wrote:
 And,  BTW, this bottom posting has started just two or three years ago
 when Thunderbird came in place.

You obviously have no clue what you are talking about. Since email
began bottom posting was the standard. It wasn't until the sheeple who
drink the Microsoft kool-aid came along that people started
top-posting.

And Thunderbird came out in 2003, not 'two or three years ago.'

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

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



Re: [PHP] Class and interface location

2011-01-19 Thread Larry Garfield
On Wednesday, January 19, 2011 8:56:50 pm Tommy Pham wrote:

  And actually, thinking about it, I wonder if requiring the explicit
 declaration
  is a good thing anyway because then it's immediately obvious and
  greppable what the class does. :-)
  
  --Larry Garfield
 
 You mean requiring explicit declaration of
 
  class Bob implements Foo {
  
  }
 
 It's so you can guarantee your app from future breakage because the
 interface guarantees minimum functionality and still maintain great
 flexibility such that:

Well, let me offer a more precise example of what I want to do:

interface Stuff {
  function doStuff($a);
}

interface Things extends Stuff {
  function doThings($a);
}

class Bob implements Stuff {...}

class Alice implements Stuff {...}

class George {}

class Matt implements Things {...}


function make_stuff_happen($o) {
  foreach (class_that_implements_stuff() as $class) {
$c = new $class();
$c-doStuff($o);
  }
}

The above code should iterate over Bob, Alice, and Matt, but not George.  The 
trick is how to implement class_that_implements_stuff() (or rather, 
class_that_implements_something('Stuff')) in a sane and performant fashion 
that supports auto-loading.

If all of the above is together in a single file, it's dead simple with 
get_declared_classes() and class_implements().  However, in practice there 
could be some 200 interfaces -- with each installation having a different set 
of them -- and as many as 500 classes implementing some combination of those 
interfaces, possibly multiple on the same class -- also with each installation 
having a different set of them.  I do not want to be forced to include all of 
those classes and interfaces on every page load when in practice only perhaps 
two dozen will be needed on a particular request.  That makes 
class_that_implements_stuff() considerably tricker.

That let naturally to having a cached index (in a database, in a file with a 
big lookup array, whatever) that pre-computed which class implements what 
interface and what file it lives in, so that we can easily lookup what classes 
we need and then let the autoloader find them.  (Previous benchmarks have 
shown that an index-based autoloader is actually pretty darned fast.)  That 
just makes building that index the challenge, hence this email thread.

Thinking it through, however, I am now wondering if, in practice, indirect 
implementation (class Matt above) will even be that common.  It may not be 
common enough to be an issue in practice, so requiring Matt to be declared as:

class Matt implements Stuff, Things {...}

isn't really that big of a deal and makes the indexer considerably simpler.  
We actually have one already that indexes class locations; it just doesn't 
track interfaces.  

I also, on further review, don't think that class-based inheritance will ever 
be an issue.  The following:

class Mary extends Alice {...}

Would not make much sense at all because then both Mary and Alice would run, 
so Alice's code would run twice.  So I may be over-complicating the situation.

(For those following along at home, yes, this is essentially observer pattern.  
However, it's on a very large scale and the thing being observed may not 
always be an object, so the usual active registration process of instantiating 
both objects and telling them about each other on the off chance that they 
*may* be needed is excessively wasteful.)

Does that make it clearer what I'm trying to do?

--Larry Garfield

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



[PHP] Class and interface location

2011-01-18 Thread Larry Garfield
Hi all.  I'm trying to come up with a solution to an architectural problem I 
could use some extra eyes on.

I have (or will have) a large code base with lots of classes, spread out over 
many optional plugin components.  These classes, of course, will have 
interfaces on them.  These classes will, of course, lazy-load using PHP's 
autoload capability.

What I need to know is which classes implement which interfaces, so that I can 
load and use all classes that implement interface Foo.  

There are a couple of approaches that I've considered, all of which I dislike 
for one reason or another.

1) Magic file naming.  That is, any class that implements interface Foo lives 
in a $something.Foo.inc file, or some similar pattern.  This has a number of 
problems.  First, it means a huge number of file_exists() calls to determine 
if a given potential class exists, and then disk hits to load those files.  
While that information is possible to cache, it also means that we cannot have 
a class that implements two of the interfaces I'm interested in (a feature I 
will need) because then it would have to live in two files, which is clearly 
impossible.

2) Reflection.  PHP makes it quite easy to get a list of all loaded classes, 
and to get a list of all interfaces that a loaded class implements.  The catch 
there is loaded.  Reflection only works once you've loaded the code file 
into memory.  Once you've done so, you cannot unload it.  That means the code 
is sitting there in memory wasting space.  Given the size of the code base in 
question, that could easily blow out the process memory limit.  Even if we 
cache that information we derive from reflection we still have to load it the 
first time (or periodically when rebuilding the cache), which will blow the 
memory limit.  The only alternative would be to have some sort of incremental 
rebuild across a multi-request batch process, the complexity of which makes my 
skin crawl.

3) Static analysis.  Instead of reflection, either tokenize or string parse 
all files to determine what classes implement what interfaces and then cache 
that information.  We are actually using this method now to locate classes, 
and it works surprisingly well.  Because we never parse code into memory it 
does not ever spike the memory usage.  However, it is impossible to determine 
if a class implements a given interface by static analysis unless it declare 
so itself with the implements keyword.  If it does so indirectly via 
inheritance, either via the class or via the interface, it would not find it.  
That necessitates that any detectable classes must explicitly themselves 
declare their interfaces, even if it is redundant to do so.  I don't like that 
approach, but it's the first one that strikes me as even viable.

4) Explicit declaration.  In this approach we detect nothing and rely on the 
plugin developer to do everything.  That is, they must provide somewhere 
(either in code or a configuration file) an index of all classes they offer, 
the interfaces they implement, and the file in which they live.  While this 
makes the implementation easy, it is a huge burden on the plugin developer and 
I'm quite sure they'll forget to do so or get it wrong on a regular basis.

5) Wave a wand and let the magic ponies figure it out.  I wish. :-)

Can anyone suggest a better alternative?  At the moment option 3 seems like 
the most viable approach, but I'm not wild about the implied performance 
impact nor the potentially redundant interface definitions it would require.

--Larry Garfield

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



Re: [PHP] Closure and $this

2011-01-12 Thread Larry Garfield
On Wednesday, January 12, 2011 11:37:19 pm Greg Bair wrote:
 On Wed, 12 Jan 2011 20:02:11 -0800 (PST)
 
 Raymond Irving xwis...@yahoo.com wrote:
  Hello,
  Does anyone know if closures will ever support the $this keyword? 
  I think it would be very useful when working with objects.
  
  Best regards__RaymondDo more with less - http://raxanpdi.com
 
 Probably not, and my understanding of why comes from this line from the
 docs (http://www.php.net/manual/en/functions.anonymous.php):
 
 Anonymous functions are currently implemented using the Closure class.
 
 So, in other words, your closure does not belong to the class you
 declare it in, but the Closure class.
 
  Thus, if it supported the $this variable, it would refer not to the
  class you want, but instead to the Closure class.
 
 Just my understanding.  If it's not right, someone point it out.

Actually at one point early on they did support a $this, but the way it was 
bound to an object was half-assed and incomplete so it was removed entirely 
from 5.3.  The intent was to then properly think through how that binding 
should happen and re-introduce it properly in 5.4.  I believe a consensus was 
reached on how that should happen but I'm not sure what its implementation 
status is at present.

I believe this is the relevant RFC:

http://wiki.php.net/rfc/closures/object-extension

--Larry Garfield

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



Re: [PHP] Command line PHP

2011-01-07 Thread Larry Garfield
On Friday, January 07, 2011 9:34:42 pm David Hutto wrote:

 Which yielded this as the first result:
 
 
 http://php.net/manual/en/features.commandline.php

As noted in my original email, I find the native SAPI clunky and difficult to 
work with.  Hence I was looking for something more usable and robust built on 
top of it that I could leverage rather than rolling my own one-off.  Of 
course, I got lost somewhere in the language holy wars (dear god, people...) 
so I'll probably just take the roll my own approach.

--Larry Garfield

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



Re: [PHP] Newbie Question

2011-01-02 Thread Larry Garfield
On Sunday, January 02, 2011 4:56:28 pm Adolfo Olivera wrote:
 Thanks for the replies. I'll just put a php on all my html containing php.
 A little of topic. Wich IDE are you guys using. I'm sort of in a catch
 twenty two here. I been alternating vim and dreamweaver. I'm trying to go
 100% open source, but I really find dreamweaver easier to use so far.

I bounce between NetBeans and Eclipse, depending on which currently sucks 
less.  I have yet to find a PHP IDE that doesn't suck; it's just degrees of 
suckage. :-)

--Larry Garfield

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



Re: [PHP] PDO: good, popular?

2010-12-14 Thread Larry Garfield
On Tuesday, December 14, 2010 1:02:33 pm Lester Caine wrote:
 la...@garfieldtech.com wrote:
  I'm the DB maintainer for Drupal 7, and we rebuilt our entire DB layer
  on top of PDO.  It's a rather nice API, although as others have noted it
  does not abstract away SQL entirely; it abstracts the API calls you need
  to use to get to SQL.
  
  We then built a layer on top of that which does abstract away most
  database weirdness using fluent query builders.  It's much
  lighter-weight than an ORM.  I'm in the process of spinning it off as a
  stand-alone library because we think it's that cool, but it's not
  completely divorced from Drupal yet.  Stay tuned. :-)
 
 Larry - how many databases does it actually work with? Having rebuilt the
 DB layer using PDO did you actually gain anything?

Drupal 6 and earlier supported MySQL and, kinda sorta, Postgres, maybe.

Drupal 7 ships with support for MySQL, Postgres, and SQLite out of the box and 
add-on modules provide support for Oracle and MS SQL, within reason.  So we 
increased our DB support from 1.5 to 5, essentially.

We also gained, as part of the rewrite, untyped prepared statements, 
transactions, and master/slave support (although that's nothing to do with PDO 
per se, just our layer on top of it).  And that allowed us, in turn, to build 
type-safe query builders, support for MERGE queries, and all kinds of other 
fun stuff on top of that.

 PDO still needs a number of areas finishing before it can become a total
 replacement for the legacy stuff that is available such as the PEAR
 libraries and the likes of Drupal writing their own abstraction layer on
 top of it ... along with a number of other projects who are now doing the
 same thing ... shows that PDO is not creating the common platform it was
 supposed to :(

That is, sadly, true.  PDO is not a complete and perfect DB library, in part 
because there are few people who work on it, and fewer still who understand 
all of the vendor-specific issues at hand and the vendors have been very slow 
to lend a hand, preferring to work on proprietary APIs.  It's quite 
unfortunate, but I still consider PDO an overall win.

If anyone knows C and wants to make a name for themselves in the PHP world, 
PDO is looking for some heroes. :-)

--Larry Garfield

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



Re: [PHP] ORM doctrine

2010-12-09 Thread Larry Garfield
On Thursday, December 09, 2010 12:45:38 pm David Harkness wrote:
 On Wed, Dec 8, 2010 at 11:11 PM, Daevid Vincent dae...@daevid.com wrote:
  Avoid these ORM things like the plague! . . . Not to
  mention all that fancy ORM doesn't come without a price. It costs in
  terms
  of speed, as well as training.
 
 If you value CPU time over developer time, by all means avoid ORM
 frameworks (and *all* frameworks). The point of a common framework is to
 trade a small bit of performance for a large amount of developer time. If
 you will only use the framework once, the payoff will be much less. The
 goal is to choose frameworks that you can leverage again and again.
 
 As for training, you will be able to hire another developer that knows
 Doctrine. It will be impossible to find a developer *anywhere* that
 understands your home-grown framework without training. Nor will you get
 help with bugs in your framework or be able to discuss better ways to use
 it on forums.
 
 That being said, there are times when it's better to write your own code. I
 will do this if the options out there don't suit my needs or if they seem
 under-supported. For example, while we use PHPUnit and Zend MVC in our
 apps, I wrote my own TestCase subclasses instead of using Zend's. I had to
 write documentation for the other developers, and I must maintain it as
 needs change. It was not a decision I took lightly.
 
 David

ORMs are fundamentally fighting the wrong battle.  They have their use, but in 
general they are architecturally not something you want to build your entire 
system on.

See:
http://www.garfieldtech.com/blog/orm-vs-query-builders
http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx

--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



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



Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Larry Martell
On Thu, Oct 21, 2010 at 1:37 PM, sueandant hollandsath...@tiscali.co.uk wrote:
 Hi

 I'm not familiatr with the term top-post; could you please explain?


http://idallen.com/topposting.html

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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Larry Martell
On Thu, Oct 14, 2010 at 9:45 AM, Paul M Foster pa...@quillandmouse.com wrote:
 Folks:

 Being fairly geezerly, I know almost nothing about this, so be gentle.

 Assuming someone entered information in a form on a website. Normally,
 you would email the responses to someone. But what if you wanted to
 send this information to a smartphone via text messaging?

 Is this possible, given normal programming tools (PHP/Javascript), or
 would you have to go through some commercial web to text messaging
 gateway? Does anyone know if this could be done, and how?

You can send a text message via email:

Verizon: 10digitphonenum...@vtext.com
ATT: 10digitphonenum...@txt.att.net
Sprint: 10digitphonenum...@messaging.sprintpcs.com
T-Mobile: 10digitphonenum...@tmomail.net
Nextel: 10digitphonenum...@messaging.nextel.com
Cingular: 10digitphonenum...@cingularme.com
Virgin Mobile: 10digitphonenum...@vmobl.com
Alltel: 10digitphonenum...@message.alltel.com
CellularOne: 10digitphonenum...@mobile.celloneusa.com
Omnipoint: 10digitphonenum...@omnipointpcs.com
Qwest: 10digitphonenum...@qwestmp.com

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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Larry Martell
On Thu, Oct 14, 2010 at 10:01 AM, Sebastian Detert
php-maill...@elygor.de wrote:
 Larry Martell schrieb:

 On Thu, Oct 14, 2010 at 9:45 AM, Paul M Foster pa...@quillandmouse.com
 wrote:


 Folks:

 Being fairly geezerly, I know almost nothing about this, so be gentle.

 Assuming someone entered information in a form on a website. Normally,
 you would email the responses to someone. But what if you wanted to
 send this information to a smartphone via text messaging?

 Is this possible, given normal programming tools (PHP/Javascript), or
 would you have to go through some commercial web to text messaging
 gateway? Does anyone know if this could be done, and how?


 You can send a text message via email:

 Verizon: 10digitphonenum...@vtext.com
 ATT: 10digitphonenum...@txt.att.net
 Sprint: 10digitphonenum...@messaging.sprintpcs.com
 T-Mobile: 10digitphonenum...@tmomail.net
 Nextel: 10digitphonenum...@messaging.nextel.com
 Cingular: 10digitphonenum...@cingularme.com
 Virgin Mobile: 10digitphonenum...@vmobl.com
 Alltel: 10digitphonenum...@message.alltel.com
 CellularOne: 10digitphonenum...@mobile.celloneusa.com
 Omnipoint: 10digitphonenum...@omnipointpcs.com
 Qwest: 10digitphonenum...@qwestmp.com



 Me again ;) Is that for free? I just found this interesting site:
 http://www.tech-faq.com/how-to-send-text-messages-free.html

Yes, you can send text messages for free this way.

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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Larry Martell
On Thu, Oct 14, 2010 at 10:29 AM, Sebastian Detert
php-maill...@elygor.de wrote:
 Larry Martell schrieb:

 On Thu, Oct 14, 2010 at 10:01 AM, Sebastian Detert
 php-maill...@elygor.de wrote:


 Larry Martell schrieb:

 On Thu, Oct 14, 2010 at 9:45 AM, Paul M Foster pa...@quillandmouse.com
 wrote:


 Folks:

 Being fairly geezerly, I know almost nothing about this, so be gentle.

 Assuming someone entered information in a form on a website. Normally,
 you would email the responses to someone. But what if you wanted to
 send this information to a smartphone via text messaging?

 Is this possible, given normal programming tools (PHP/Javascript), or
 would you have to go through some commercial web to text messaging
 gateway? Does anyone know if this could be done, and how?


 You can send a text message via email:

 Verizon: 10digitphonenum...@vtext.com
 ATT: 10digitphonenum...@txt.att.net
 Sprint: 10digitphonenum...@messaging.sprintpcs.com
 T-Mobile: 10digitphonenum...@tmomail.net
 Nextel: 10digitphonenum...@messaging.nextel.com
 Cingular: 10digitphonenum...@cingularme.com
 Virgin Mobile: 10digitphonenum...@vmobl.com
 Alltel: 10digitphonenum...@message.alltel.com
 CellularOne: 10digitphonenum...@mobile.celloneusa.com
 Omnipoint: 10digitphonenum...@omnipointpcs.com
 Qwest: 10digitphonenum...@qwestmp.com



 Me again ;) Is that for free? I just found this interesting site:
 http://www.tech-faq.com/how-to-send-text-messages-free.html


 Yes, you can send text messages for free this way.



 I just tried it. I guess, it is only possible to use those E-Mails if you
 are a customer of that phone company, right? I tried it with my own provider
 (O2 germany),
 sending an email to phonenum...@o2online.de failed, I had to activate that
 serviceby sending +OPEN to 6245, but every email to sms costs money ...
 Are you sure it is possible to send sms to phones around the world to any
 provider? How do u distinguish between provider and country?

 I'm sorry if I'm asking stupid stuff

I have no idea how it works in other countries or with every single
provider. I do know that here in the US I do it all the time with the
carriers I listed above. I have cron based monitors that text people
via email when there are problems.

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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Larry Martell
On Thu, Oct 14, 2010 at 9:56 AM, chris h chris...@gmail.com wrote:
 You can send a text message via email:
    Verizon: 10digitphonenum...@vtext.com
    ATT: 10digitphonenum...@txt.att.net
    Sprint: 10digitphonenum...@messaging.sprintpcs.com
    T-Mobile: 10digitphonenum...@tmomail.net
    Nextel: 10digitphonenum...@messaging.nextel.com
    Cingular: 10digitphonenum...@cingularme.com
    Virgin Mobile: 10digitphonenum...@vmobl.com
    Alltel: 10digitphonenum...@message.alltel.com
    CellularOne: 10digitphonenum...@mobile.celloneusa.com
    Omnipoint: 10digitphonenum...@omnipointpcs.com
    Qwest: 10digitphonenum...@qwestmp.com


 Larry, it seems like this method would only be useful if you knew the
 carrier of a specific number.  Do you know of a way to determine that?

http://www.fonefinder.net/

--
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
 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



[PHP] Retaining scroll position after asynchronous refresh

2010-07-23 Thread Larry Martell
Hello all-

I have a php script that generates a web page with a bunch of
scrollable frames, and then asynchronously refreshes the page. If the
user has scrolled down in any of the frames, when the refresh occurs
it has scrolled back to the top of all the frames. Is there a way I
can retain the scroll position so after the refresh the frames are
shown at the same location as before the refresh? I have googled and
googled for this, but everything I find is ASP or C# or Java. My stuff
is straight php/html. How can I do this with that?

TIA!
-larry

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



[PHP] running out of memory processing result set on Linux, but not on Solaris

2010-07-13 Thread Larry Martell
I have an app that runs just fine on an older Solaris apache server
(Apache/2.0.53 PHP/5.0.4), but when I run the same app on a newer
Linux server (Apache/2.2.3-11 PHP/5.2.8) against the same database on
the same mysql server, it fails with Allowed memory size exhausted.
This occurs on a:

$result = mysql_query($query, $db)

statement. Both servers are running the identical query, which returns
a result set under 0.5M. The Solaris server is configured with
memory_limit = 8M in php.ini, and the Linux one with 32M, so clearly
something other then what I'm seeing is going on. Anyone know what
could be causing this? Any php or apache build or config options that
I could look at?

TIA!

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



Re: [PHP] running out of memory processing result set on Linux, but not on Solaris

2010-07-13 Thread Larry Martell
On Tue, Jul 13, 2010 at 11:11 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:

 On Tue, 2010-07-13 at 11:06 -0600, Larry Martell wrote:

 I have an app that runs just fine on an older Solaris apache server
 (Apache/2.0.53 PHP/5.0.4), but when I run the same app on a newer
 Linux server (Apache/2.2.3-11 PHP/5.2.8) against the same database on
 the same mysql server, it fails with Allowed memory size exhausted.
 This occurs on a:

 $result = mysql_query($query, $db)

 statement. Both servers are running the identical query, which returns
 a result set under 0.5M. The Solaris server is configured with
 memory_limit = 8M in php.ini, and the Linux one with 32M, so clearly
 something other then what I'm seeing is going on. Anyone know what
 could be causing this? Any php or apache build or config options that
 I could look at?

 TIA!


 Is there any other place which your code is changing the memory_limit 
 parameter? I would assume this is unlikely, but sometimes even the unlikely 
 happens more than than it should!

The error message actually says Allowed memory size of 3355432 bytes
exhausted so I know it's using the 32M that it's set to php.ini. But
as I wrote above, on the Solaris server where it works, the
memory_limit is set to 8M.

 Can you maybe strip the code down to a test case which causes the error?

I've already done that - all it does it run a query and display the results.

 Lastly, I do notice that you've got two different versions of PHP  Apache 
 installed on each OS, which could be the reason for the failure.

Well, yes, that's what I said. And they may been built with different
config options. But what options could cause a difference like this?

 Maybe set up a VM or two to test things out. Have one VM with Solaris and 
 Apache/2.2.3-11  PHP/5.2.8, and another VM with Apache/2.0.53  PHP/5.0.4 
 and see what happens. It could be that it's either Apache or PHP or both
 causing the problems on your Linux system.

I don't have control of that. This is at a client site - they want to
get rid of their existing older Solaris apache server and move to a
newer Linux one. The servers are already set up they way they are. I
asked the admis for info on the build - they have it for the newer
Linux one, but not for the older Solaris one. They did give me another
machine to test on - that one is Linux, Apache 2.2.3, PHP 5.2.6 - that
also gets the out of memory error.

-- 
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 simples...@gmail.comwrote:
   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] 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] 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



[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] 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



[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



  1   2   3   4   5   6   7   8   9   >