php-general Digest 3 Jun 2012 09:03:00 -0000 Issue 7838

Topics (messages 318102 through 318114):

Re: Using default argument values in the middle of the argument list
        318102 by: Matijn Woudt
        318111 by: oliver gondža
        318112 by: Matijn Woudt

Re: Simple Email System (SES) Provider
        318103 by: Matijn Woudt
        318104 by: Ashley Sheridan
        318105 by: Stuart Dallas
        318106 by: Ashley Sheridan
        318107 by: Matijn Woudt
        318108 by: Matijn Woudt

Re: is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all 
lowercase?
        318109 by: Govinda

About sessions and subdomains
        318110 by: Andre Polykanine

Re: Open Call: Official PHP Mirror
        318113 by: Paul M Foster

Re: Function size
        318114 by: Tony Marston

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Fri, Jun 1, 2012 at 9:52 PM,  <324...@mail.muni.cz> wrote:
> Hi,
>
> as I accidentally found out that PHP allows default argument values
> to occur not only at the end of parameter list:
>
> function ( Classname $a, Classname $b = null, Classname $c ) ...
>
> Unfortunately, documentation does not state what is supposed to happen in
> such situation.
> It appears $b can be an instance of Classname or a null.
>
> I've draw up simple test case (https://gist.github.com/2829626) to verify my
> assumption
> and it seems to work at least since PHP 5.3.0. It is extremely useful to
> allow null
> value and retain the power of type hints at the same time.
>
> Is there anything else to test? Does it work for your setup? Can it be used
> that way?
> And if yes, can it be officially documented?
>
> Do not hesitate to prove I'm wrong.
>
> -- Oliver
>

Hi Oliver,

I think the example at [1] demonstrates that it is possible, but it
also notes that it is pretty useless. Why are you interested in this?

- Matijn

[1] http://www.php.net/manual/en/functions.arguments.php#example-153

--- End Message ---
--- Begin Message ---
On Sat, 02 Jun 2012 17:13:55 +0200, Matijn Woudt <tijn...@gmail.com> wrote:


Hi Oliver,

I think the example at [1] demonstrates that it is possible, but it
also notes that it is pretty useless. Why are you interested in this?

- Matijn

[1] http://www.php.net/manual/en/functions.arguments.php#example-153

Hi,

Thanx for your response.

PHP class type hints are bit more restrictive than in say Java
since it does not accept null as a value of a class. This provides
great guarantees, however, sometimes it is desirable to allow null as well.

This can be done using:

function func ( Classname $a = null )

Unfortunately, according to documentation this will work only at the end of
parameter list. So this restriction force you to put nullable arguments at
the end of argument list or not use type hints at all. In the worst case
scenario you have to choose between use of illogical order of arguments,
reimplementation of type hinting for arguments that comes after the
nullable one or use no type hinting at all for nullable arguments:

function func ( Classname $last, Classname $first = null ) {
  ...
}

or

function func ( Classname $first = null, Classname $last = null ) {
  if ( $last === null ) throw new InvalidArgumentException;
  ...
}

or

function func ( $first, Classname $last ) {
if ( !( $first instanceof Classname ) ) throw new InvalidArgumentException;
  ...
}

This is not ideal especially if the desired solution seems to work:

function func ( Classname $first = null, Classname $last ) {
  ...
}

This function expects exactly two arguments. The second one is supposed to be an instance of Classname and the first one may be an instance of Classname or null.

This might be useless for primitive values since any default value you can define can be provided from the outside as well. But, it is definitely not useless for objects since you can not pass null value as an argument that requires an object of some class. As far as i can tell this can emulate Java style object type handling
when you needed it. I would be glad to rely on such a behavior.

-- Oliver

--- End Message ---
--- Begin Message ---
On Sat, Jun 2, 2012 at 8:30 PM, oliver gondža <ogon...@gmail.com> wrote:
> On Sat, 02 Jun 2012 17:13:55 +0200, Matijn Woudt <tijn...@gmail.com> wrote:
>
>>
>> Hi Oliver,
>>
>> I think the example at [1] demonstrates that it is possible, but it
>> also notes that it is pretty useless. Why are you interested in this?
>>
>> - Matijn
>>
>> [1] http://www.php.net/manual/en/functions.arguments.php#example-153
>
>
> Hi,
>
> Thanx for your response.
>
> PHP class type hints are bit more restrictive than in say Java
> since it does not accept null as a value of a class. This provides
> great guarantees, however, sometimes it is desirable to allow null as well.
>
> This can be done using:
>
> function func ( Classname $a = null )
>
> Unfortunately, according to documentation this will work only at the end of
> parameter list. So this restriction force you to put nullable arguments at
> the end of argument list or not use type hints at all. In the worst case
> scenario you have to choose between use of illogical order of arguments,
> reimplementation of type hinting for arguments that comes after the
> nullable one or use no type hinting at all for nullable arguments:

It does not state it works only at the end of the list, it states that
it only makes sense to use it at the end of the argument list to be
able to call the function with less arguments. In case you want to use
it as suggested in [2], you can use it anywhere. You can rely on that
in any PHP version from 5 upwards, just because version 4 doesn't
support type hinting at all.

- Matijn

[2] http://php.net/manual/en/language.oop5.typehinting.php

--- End Message ---
--- Begin Message ---
On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
> Hi all,
>
> I built a system in PHP/mySQL where a group of users post events, sign-up
> for events, change their arrival times, remove thier names from events, and
> post related notes on the events. Each time an action is done, an email is
> generated to the entire group that their has been a change. Pretty standard
> stuff...
>
> Today I just got an Mail Delivery System email with this error:
>
> Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
> allowed.  Message will be reattempted later
>
> I contacted my VPS provider and they just alerted me that there is a limit
> on how many emails my server can send per hour.
>
> They recommended I find a 3rd party service provider with support PHP API
> connections.
>
> My budget is limited. Does anyone have any suggestions of companies that
> might work for my scenario?
>
> Any feedback is appreciated ;-)
>
> Don
>

Maybe you can group all mails to a single group together (with
contacts in BCC), so you only need to send 1 mail instead of 100 for a
group of 100 users?

- Matijn

--- End Message ---
--- Begin Message ---
On Sat, 2012-06-02 at 17:33 +0200, Matijn Woudt wrote:

> On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
> > Hi all,
> >
> > I built a system in PHP/mySQL where a group of users post events, sign-up
> > for events, change their arrival times, remove thier names from events, and
> > post related notes on the events. Each time an action is done, an email is
> > generated to the entire group that their has been a change. Pretty standard
> > stuff...
> >
> > Today I just got an Mail Delivery System email with this error:
> >
> > Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
> > allowed.  Message will be reattempted later
> >
> > I contacted my VPS provider and they just alerted me that there is a limit
> > on how many emails my server can send per hour.
> >
> > They recommended I find a 3rd party service provider with support PHP API
> > connections.
> >
> > My budget is limited. Does anyone have any suggestions of companies that
> > might work for my scenario?
> >
> > Any feedback is appreciated ;-)
> >
> > Don
> >
> 
> Maybe you can group all mails to a single group together (with
> contacts in BCC), so you only need to send 1 mail instead of 100 for a
> group of 100 users?
> 
> - Matijn
> 


I would assume that each recipient would count as a single email, so if
you send one email to 150 people, you'd be 25% through the hourly quota.
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 2 Jun 2012, at 17:20, Ashley Sheridan wrote:

> On Sat, 2012-06-02 at 17:33 +0200, Matijn Woudt wrote:
> 
>> On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
>>> Hi all,
>>> 
>>> I built a system in PHP/mySQL where a group of users post events, sign-up
>>> for events, change their arrival times, remove thier names from events, and
>>> post related notes on the events. Each time an action is done, an email is
>>> generated to the entire group that their has been a change. Pretty standard
>>> stuff...
>>> 
>>> Today I just got an Mail Delivery System email with this error:
>>> 
>>> Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
>>> allowed.  Message will be reattempted later
>>> 
>>> I contacted my VPS provider and they just alerted me that there is a limit
>>> on how many emails my server can send per hour.
>>> 
>>> They recommended I find a 3rd party service provider with support PHP API
>>> connections.
>>> 
>>> My budget is limited. Does anyone have any suggestions of companies that
>>> might work for my scenario?
>>> 
>>> Any feedback is appreciated ;-)
>>> 
>>> Don
>>> 
>> 
>> Maybe you can group all mails to a single group together (with
>> contacts in BCC), so you only need to send 1 mail instead of 100 for a
>> group of 100 users?
>> 
>> - Matijn
>> 
> 
> 
> I would assume that each recipient would count as a single email, so if
> you send one email to 150 people, you'd be 25% through the hourly quota.

Dunno how mathematics works in your universe, but 4 * 150 != 350 in the one in 
which I live :)

Don: Options...

* Switch to a dedicated server, or a VPS host that doesn't have that limit.

* Use Gmail or another hosted email provider (may have a similar limit but I've 
never run into it with Gmail).

* Use a service like http://sendgrid.com/.

-Stuart

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

--- End Message ---
--- Begin Message ---
On Sat, 2012-06-02 at 17:25 +0100, Stuart Dallas wrote:

> On 2 Jun 2012, at 17:20, Ashley Sheridan wrote:
> 
> > On Sat, 2012-06-02 at 17:33 +0200, Matijn Woudt wrote:
> > 
> >> On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
> >>> Hi all,
> >>> 
> >>> I built a system in PHP/mySQL where a group of users post events, sign-up
> >>> for events, change their arrival times, remove thier names from events, 
> >>> and
> >>> post related notes on the events. Each time an action is done, an email is
> >>> generated to the entire group that their has been a change. Pretty 
> >>> standard
> >>> stuff...
> >>> 
> >>> Today I just got an Mail Delivery System email with this error:
> >>> 
> >>> Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
> >>> allowed.  Message will be reattempted later
> >>> 
> >>> I contacted my VPS provider and they just alerted me that there is a limit
> >>> on how many emails my server can send per hour.
> >>> 
> >>> They recommended I find a 3rd party service provider with support PHP API
> >>> connections.
> >>> 
> >>> My budget is limited. Does anyone have any suggestions of companies that
> >>> might work for my scenario?
> >>> 
> >>> Any feedback is appreciated ;-)
> >>> 
> >>> Don
> >>> 
> >> 
> >> Maybe you can group all mails to a single group together (with
> >> contacts in BCC), so you only need to send 1 mail instead of 100 for a
> >> group of 100 users?
> >> 
> >> - Matijn
> >> 
> > 
> > 
> > I would assume that each recipient would count as a single email, so if
> > you send one email to 150 people, you'd be 25% through the hourly quota.
> 
> Dunno how mathematics works in your universe, but 4 * 150 != 350 in the one 
> in which I live :)
> 
> Don: Options...
> 
> * Switch to a dedicated server, or a VPS host that doesn't have that limit.
> 
> * Use Gmail or another hosted email provider (may have a similar limit but 
> I've never run into it with Gmail).
> 
> * Use a service like http://sendgrid.com/.
> 
> -Stuart
> 


Yeah my bad, I'll blame it on the heat and my poor carbon-based
processor :p
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Sat, Jun 2, 2012 at 6:20 PM, Ashley Sheridan 
<a...@ashleysheridan.co.uk>wrote:

> **
> On Sat, 2012-06-02 at 17:33 +0200, Matijn Woudt wrote:
>
> On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
> > Hi all,
> >
> > I built a system in PHP/mySQL where a group of users post events, sign-up
> > for events, change their arrival times, remove thier names from events, and
> > post related notes on the events. Each time an action is done, an email is
> > generated to the entire group that their has been a change. Pretty standard
> > stuff...
> >
> > Today I just got an Mail Delivery System email with this error:
> >
> > Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
> > allowed.  Message will be reattempted later
> >
> > I contacted my VPS provider and they just alerted me that there is a limit
> > on how many emails my server can send per hour.
> >
> > They recommended I find a 3rd party service provider with support PHP API
> > connections.
> >
> > My budget is limited. Does anyone have any suggestions of companies that
> > might work for my scenario?
> >
> > Any feedback is appreciated ;-)
> >
> > Don
> >
>
> Maybe you can group all mails to a single group together (with
> contacts in BCC), so you only need to send 1 mail instead of 100 for a
> group of 100 users?
>
> - Matijn
>
>
>
> I would assume that each recipient would count as a single email, so if
> you send one email to 150 people, you'd be 25% through the hourly quota.
>   --
>

I wonder which school you went to ;) 150/350 = 42.86%..

--- End Message ---
--- Begin Message ---
On Sat, Jun 2, 2012 at 6:25 PM, Stuart Dallas <stu...@3ft9.com> wrote:
> On 2 Jun 2012, at 17:20, Ashley Sheridan wrote:
>
>> On Sat, 2012-06-02 at 17:33 +0200, Matijn Woudt wrote:
>>
>>> On Sat, Jun 2, 2012 at 2:32 AM, Don Wieland <d...@pointmade.net> wrote:
>>>> Hi all,
>>>>
>>>> I built a system in PHP/mySQL where a group of users post events, sign-up
>>>> for events, change their arrival times, remove thier names from events, and
>>>> post related notes on the events. Each time an action is done, an email is
>>>> generated to the entire group that their has been a change. Pretty standard
>>>> stuff...
>>>>
>>>> Today I just got an Mail Delivery System email with this error:
>>>>
>>>> Domain dwdcweb.info has exceeded the max emails per hour (350/350 (100%))
>>>> allowed.  Message will be reattempted later
>>>>
>>>> I contacted my VPS provider and they just alerted me that there is a limit
>>>> on how many emails my server can send per hour.
>>>>
>>>> They recommended I find a 3rd party service provider with support PHP API
>>>> connections.
>>>>
>>>> My budget is limited. Does anyone have any suggestions of companies that
>>>> might work for my scenario?
>>>>
>>>> Any feedback is appreciated ;-)
>>>>
>>>> Don
>>>>
>>>
>>> Maybe you can group all mails to a single group together (with
>>> contacts in BCC), so you only need to send 1 mail instead of 100 for a
>>> group of 100 users?
>>>
>>> - Matijn
>>>
>>
>>
>> I would assume that each recipient would count as a single email, so if
>> you send one email to 150 people, you'd be 25% through the hourly quota.
>
> Dunno how mathematics works in your universe, but 4 * 150 != 350 in the one 
> in which I live :)
>
> Don: Options...
>
> * Switch to a dedicated server, or a VPS host that doesn't have that limit.
>
> * Use Gmail or another hosted email provider (may have a similar limit but 
> I've never run into it with Gmail).
>

Stuart,

If the facts are still correct (based on numbers from 2008), Gmail has
a limit of 500 messages a day, with a maximum of reaching 2000
recipients a day.

- Matijn

--- End Message ---
--- Begin Message ---
> anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow 
> users to create their own external style sheets via form input)
[snip]
> I found how to set CSStidy's config options if I was running CSStidy from the 
> command line, or on its _own_ from PHP runtime, but I do not know how to set 
> the config options from within HTMLpurifier, or even how to hack/override 
> either of those libraries to solve my particular issue.  I looked and hacked 
> and thought for sure I would find the offending line of code.. but somehow, 
> nothing I have tried is stopping one or both of those libraries from forcing 
> all my input CSS into lowercase, which I do not want.  The issue is that I 
> need the input CSS's case to be left as the user input it (so that for 
> example background image paths in that CSS do not break).
> 
> more details:
> http://stackoverflow.com/questions/10843600/

For the archives / anyone following this thread:

Thanks to the developer of HTMLpurifier, it was just fixed here:
http://repo.or.cz/w/htmlpurifier.git/commit/f38fca32a9bad0952df221f8664ee2ab13978504

-Govinda

--- End Message ---
--- Begin Message ---
Hi everyone,
Sorry, this might be a stupid question, but still.
Once  upon  a  time  I  had  done  so  my sessions were handled on all
subdomains of my website (shame on me for doing so!).
Now, when I comment out the line
session_set_cookie_params(0, "/", ".oire.org");
in  my  header  file,  I got an empty $_SESSION array after submitting
every single form on my website.
For  sure,  signing  out and back in, as well as cookie removing, were
tried several times.
Thanks in advance!

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
Blog: http://oire.org/menelion
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion


--- End Message ---
--- Begin Message ---
On Fri, Jun 01, 2012 at 04:50:03PM -0400, Daniel Brown wrote:


[snip]

> 
>     Who should not apply?
> 
>     Third-party sponsors, those who want to try to run the mirror from
> their Blackberry, people without servers located in the respective
> country for which they're applying, shared hosting clients, Droids,
> Borg, Klingons, Romulans, toddlers, and the gum disease known as
> "gingivitis."

There I was, ready to volunteer, until I saw "Romulans". Geez, a few bad
apples spoiling it for the rest of us. Crap. ;-}

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

--- End Message ---
--- Begin Message --- "tamouse mailing lists" wrote in message news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...

On Tue, May 29, 2012 at 2:52 AM, Tony Marston
<t...@marston-home.demon.co.uk> wrote:
On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
 A rule of thumb is no more than 50 lines per
function, most much less. Back in the day when we didn't have nifty
gui screens and an 24 line terminals (yay green on black!), if a
function exceeded one printed page, it was deemed too long and marked
for refactoring.

I think the idea of setting an arbitrary limit on the number of lines that a
function should contain is quite ludicrous and something which I will
completely ignore. If a function requires a hundred or more lines then so be it. The only reason to take a block of code and put it into its own function is when that code is likely to be called more than once so that it conforms to the DRY principle. If it is only ever used in one place then there is no
point.


You obviously haven't spent much time maintaining other people's code.

I have been maintaining other people's code, which have been written to many different standards of varying quality, for many years.

There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.

I *never* have huge numbers of lines between a block beginning and end. Even if I did my IDE can quickly find the other end of the block for me.

If you will never have your code maintained by anyone else, or
collaborate with anyone else, feel free to do what you want.

My code has been available in an open source framework for over 6 years, and I have never received any complaints on the readability of my code, only compliments.


The problems I have with creating lots of small used-only-once functions is
as follows:
- you have to create a meaningful name for each function.

Yes, you do, which is also considered a hallmark of good design.

- all those functions should be arranged in alphabetical order within their
containing file - having them in a random sequence makes it difficult to
find the one you want.

Also correct; this is a key point in making sure your scripts are maintainable.

Ah-ha! So someone agrees with me on that point after all.

- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my mouse
than keep jumping from one position in the file to another.

May I suggest an editor/IDE that lets you navigate to functions directly, then?

I am *NOT* going to change my IDE just to suit *YOUR* preferences.

Another problem I have encountered in the past with such an idea is that it
encourages a stupid programmer to decrease the number of lines of code by
compressing as many statements as possible into a single line, which then
makes the code less easy to read and understand. This is much worse than
having more than 20 lines in a function.

There are counterbalancing things as well. If the only aspect of one's
coding standards are "make it fit on one screen" then yes, you might
see someone idiotic enough to do that. However, a good set of coding
standards includes things which will prevent this, such as not
stacking code like that.

Whether a file contains 10 functions of 100 lines each, or 100 functions of 10 lines each, you still end up with 1000 lines of code. If you do not have
the mental capacity to deal with a 100-line function then you are in the
wrong job.

The rules of thumb for coding standards are for maintainability,
primarily, so throwing up strawmen to try to weasel out of an idea is
pretty specious.

I will only follow standards which have a genuine purpose and a genuine benefit. I will *NOT* follow any which I consider to be arbitrary, artificial and pointless. There is *NO* limit to the number of lines in a function/method, and there is *NO* limit on the number of methods within a class. The only thing that matters is that the code is readable and maintainable. If some functions overflow the current screen then LEARN TO USE THE MOUSE WHEEL! That is what is was invented for in the first place. I will *NOT* make my code more difficult to read by creating a huge number of artificially small functions.

If you do not care about how much time it takes to fix defects in
other people's code, then I hope you remain a solitary programmer and
don't expect anyone else to use your code, otherwise, you are in the
wrong job.

I *DO* care, which is why I write code which is readable and maintainable.

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org
--- End Message ---

Reply via email to