Re: [PHP] framework or not

2013-10-26 Thread Robert Cummings

On 13-10-24 09:41 PM, Larry Garfield wrote:

On 10/23/2013 08:51 AM, Jay Blanchard wrote:

[snip] a bitter rant[/snip]

Dang Larry - bad night?


That wasn't a bitter rant.  You haven't seen me bitter. :-)  That was
"tough love" to the OP.  I don't see a reason to pussyfoot around the
original question, which is one that comes up about once a month.  The
answer is always the same: How much is your time worth?


Basic math...

Life: finite
Time: infinite

finite / infinite = 0

*sniffle*

Oh wait... you meant in the smaller scheme of things >:)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] framework or not

2013-10-22 Thread Robert Cummings

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.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Apache

2013-09-25 Thread Robert Stone





 De: Ashley Sheridan 
Para: m...@nikha.org; Domain nikha.org  
Cc: php-general@lists.php.net 
Enviadas: Quarta-feira, 25 de Setembro de 2013 2:22
Assunto: Re: [PHP] Apache
 



"Domain nikha.org"  wrote:
>Ashley Sheridan am Montag, 23. September 2013 - 21:35:
>
>> No, no, no! That is not a good stand-in for fundamental security
>> principles!
>> 
>> This is a better method for ensuring an image is really an image:
>> 
>> > if(isset($_FILES['file']))
>> {
>>     list($width, $height) = getimagesize($_FILES['file']['tmp_name']);
>>     if($width && $height)
>>     {
>>         $source = imagecreatefromjpeg($_FILES['file']['tmp_name']);
>>         $dest = imagecreatetruecolor($width, $height);
>>         
>>         imagecopyresampled($dest, $source,
>>         0, 0, 0, 0,
>>         $width, $height, $width, $height);
>>         imagejpeg($dest, basename($_FILES['file']['tmp_name']));
>>     }
>>     else
>>         echo "{$_FILES['file']['name']} is not a jpeg";
>> }
>> ?>
>> 
>>     
>>     
>> 
>> 
>> Obviously it's only rough, and checks only for jpeg images, but
>that's
>> easy to alter. I've just tested this with a regular jpeg, the same
>jpeg
>> with PHP code concatenated onto the end (which still appears to be a
>> valid image to viewing/editing software) and a pure PHP file with a
>.jpg
>> extension. In the case of the first 2, a new jpeg is generated with
>the
>> same image and without the code. The third example just echoes out an
>> error.
>> 
>
>Dear Ashley, nice, but useless for this problem!
>

The problem was to do with an image upload, so no, not useless. 

>First, because users may upload other things than images! PDF's, audio
>files, videos etc!

In an earlier email I detailed some methods for validating other types, such as 
DomDocument for HTML, XML, svg, etc, or fpdf for PDF. 

And on behalf images: GD you are using handles only
>jpeg, gif and png. There are about hunderd other image types on the
>way,

At the moment those are the 3 raster formats you can use on the web, so those 
are the ones that pose an issue. If you're using anything else, it's not for 
web and doesn't need to be in a publicly accessible location. 

>users can upload! How to detect them, if the extension is missleading?

The extension comes from the user. Never trust the user, ever.

>
>And even if we succeed: As your script demonstrates very well,
>malicious
>code does not affect the rendering of the image. 

My script does effectively strip out malicious code though, even if it can't 
easily be seen.

The hacker says: Hi,
>this is a nice picture, play it, and then, please do this--follows his
>code, that can be a desaster for the whole system.

Social engineering is a whole different issue.

>
>Yes, your script seems to purge the image file, simply because GD does
>not copy the malware code. But why are you sure about that? You cannot
>see that code, OK, but may be it was executed in the plain GD
>environement? 

GD isn't a PHP parser, and PHP doesn't execute the image before GD touches it. 
Infact, Apache isn't even involved between GD and the image at that point, so 
it won't suffer from this bad config.

What you are doing is dangerous, because you force the
>execution of things that should be never executed!

Erm, no, the image isn't being executed.

>
>"no no no" forget it. After all we cannot exclude that users come in
>with malware. 

If you think it's fine that a user be able to upload malware, then you're going 
to have a very bad time.

But we MUST exclude, it is executed on the web server.

This is important too, but in this profession belt and braces is best I 
believe. 

>That is the Apache chainsaw massacre as Steward whould say. And
>probably
>it can be avoided by purging the filenames (not the files!). 
>
>Nevertheless, the standard configuration of the Apache servers is
>basically unacceptable. It must execute user requests and never ever
>user files! Period.
>
>Have nice days,
>Niklaus 
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

Thanks,
Ash

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


Sorry for this late post but I'm amazed nobody consulted the doco.

The php.net site has a whole section titled "Handling File Uploads".
Also check out finfo_open and finfo_file.
If your are a windoze user you need a dll.
If you want Apache to handle PUT requests you MUST tell it to run a script as 
it cannot write to web root.

HTH

Robert

Re: [PHP] Static utility class?

2013-09-05 Thread Robert Cummings

On 13-09-05 02:27 PM, Micky Hulse wrote:

On Wed, Sep 4, 2013 at 11:07 PM, Robert Cummings  wrote:

I'll second Rodrigo's opinion, but would like to comment that the name of
the class is misleading since it's called "Singleton". The singleton pattern
is used when you only ever want one instantiation of a class. In your case
you are using static methods, the object never needs to be instantiated and
so it doesn't fit this pattern. What you are creating is far more consistent
with the utility pattern.


Ahhh, thanks so much for the clarification and details! That's very helpful.

I've updated my gist to reflect the pattern name:

<https://gist.github.com/mhulse/6441525>

Much appreciated. :)


Probably sufficient (and easier for typing) to just call it Utility 
since it follows the pattern but isn't the pattern itself :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Static utility class?

2013-09-04 Thread Robert Cummings

On 13-09-04 09:06 PM, Micky Hulse wrote:

Hi Rodrigo, thanks for the help, I really appreciate it!

On Wed, Sep 4, 2013 at 5:55 PM, Rodrigo Santos
 wrote:

Hi, first, sorry for the bad English.


Not bad at all! Very clear and well written reply (heck, it's better
than my native English writing), so thank you! :)


Yes, at least, as far as I know, this is the perfect way to do what you want
to do. Think like this: when you instanciate a class, you are allocating
memory. If you don't need any information stored, then you don't need to
allocate memory, right? So, it's is logic to have a class that you will call
only one fragment when you need it, rather than load the entire class just
for one method.


Interesting! That makes a lot of sense.

Now you've piqued my interests! :)

I was going to head down a different path, but you've inspired me to
further explore the use of static methods/properties/variables/other.

A part of me just wants to learn more about PHP OOP, and using static
members is something I've not explored much. Seems like a simple
functional utility class would be a good time to play and learn more.
:D


Just be careful to organize your utility methods by by meaning. Don't put a
method that make dating stuff and a method that write a random string in the
same class. By doing so, you are breaking the object orientation purpose.


Excellent tip! Thank you Rodrigo! I really appreciate the tips/advice
and inspiration. :)


I'll second Rodrigo's opinion, but would like to comment that the name 
of the class is misleading since it's called "Singleton". The singleton 
pattern is used when you only ever want one instantiation of a class. In 
your case you are using static methods, the object never needs to be 
instantiated and so it doesn't fit this pattern. What you are creating 
is far more consistent with the utility pattern.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] exec and system do not work

2013-08-25 Thread Robert Cummings

On 13-08-25 11:41 PM, Ethan Rosenberg wrote:

Dear List -

I'm lost on this one -

This works -

$out = system("ls -l ",$retvals);
printf("%s", $out);

This does -

echo exec("ls -l");

This does not -

if( !file_exists("/var/www/orders.txt"));
{
 $out = system("touch /var/www/orders.txt", $ret);
 $out2 = system("chmod 766 /var/www/orders.txt", $ret);
 echo 'file2';
 echo file_exists("/var/www/orders.txt");
}

and this does not -

if( !file_exists("/var/www/orders.txt"));
{
 exec("touch /var/www/orders.txt");
 exec("chmod 766 /var/www/orders.txt");
 echo 'file2';
 echo file_exists("/var/www/orders.txt");
}

Ethan


Hi Ethan,

Is there a reason you're using shell commands to achieve the following:



Also, why are you setting the executable bit on a text file? :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] How can I submit more than 2000 items of data?

2013-08-19 Thread Robert Cummings

On 13-08-19 11:32 AM, Stuart Dallas wrote:

On 19 Aug 2013, at 16:24, Matijn Woudt  wrote:


You might want to explain how you convert form data to JSON without javascript?


PHP can do it. Ruby can do it. .NET can do it. Just because you want to use 
JSON in a web browser where Javascript is the go-to method, doesn't mean JSON 
requires Javascript.

-Stuart



Yes, of course they can do it, but then you first need to submit the POST data 
(which he could not do because of the above). Javascript is more or less the 
only way to do it (yes I know Flash….)


I wasn't speaking to his specific issue as that was solved by an earlier 
response. I was just commenting that the implied intrinsic link between JSON 
and Javascript in what he had said does not exist.


Your post didn't in anyway indicate that your response had nothing to do 
with his problem:


"I know you've had the right answer, but I think it's worth
 pointing out that use of JSON in no way requires Javascript,
 despite its name."

As such, given the requirement of POSTing over HTTP(S) and that 
JavaScript is almost certainly more frequently used than ActionScript, I 
think a JSON based solution was at least 50% linked to JavaScript.


:)

Cheers,
Rob
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Finally....

2013-08-16 Thread Robert Cummings

On 13-08-16 11:58 AM, Marc Guay wrote:

Those Belgacom emails were the only thing keeping me from a crushing
loneliness - undo!


*sniffle* Another friend bites the dust *sniffle*.


--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

On 13-08-01 05:14 PM, Paul M Foster wrote:

On Thu, Aug 01, 2013 at 02:35:04PM -0500, Larry Garfield wrote:

[snip]



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?


Unless my wife creates the form in Dreamweaver, I write the HTML for the
form fields. Even when she does, I add the proper code to validate each
field and the form overall, using my field validation class, etc.



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.


A-ha! That's where you're wrong, Matey! For I am SUPER-CODER! Faster
than a speeding 300 baud modem! More powerful than a teletype! Able
to leap tall procedural functions at a single bound! With my pocket
protector and trusty slide rule, I defend the indefensible and champion
the cause of spaghetti code!

So there! ;-P


I often get paid to fix such code... keep up the questionable 
methodologies ;)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

On 13-07-28 01:51 PM, Jim Giner wrote:


On 7/28/2013 1:38 PM, Ashley Sheridan wrote:

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

On 7/28/2013 1:26 PM, Larry Garfield wrote:

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


Your name: 
Your age: 

In 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

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

IN answer to OP - yes you can use a single script to handle your from
return.  I do that too!  I start by recognizing my first time thru and
send out a form/page.  I process the submit back from that page, doing
something based on the label of the submit button that I detect.  I may
then do some more processing and produce a newer version of the same
form/page and repeat.  Or I may end it all at that point.  Depends on
what the overall appl is doing.

And now I'll watch and see how much I'm doing wrong.



I don't think there's anything inherently wrong with writing your own
form processing code, as long as you understand what's going on. Many
frameworks do make this a lot easier though, but sometimes I find it
encourages you to ignore some of the details (like security) because
you "know" the framework handles that stuff.

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

Thanks,
Ash
http://www.ashleysheridan.co.uk



I dont' know that i'll ever use a framework.  Strictly an
ex-professional here doing my own website stuff.  As you say 'code your
own forms first as a learning experience'.  Well, once I've coded them
(aside: I think you mean 'process', not code) and learned how to do it
right, why should I give up that task and pick up a framework?


Chances are, once you've done this yourself and abstracted away the 
implementation details, you have your own framework for performing this 
generally tedious task :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

On 13-07-28 01:14 PM, iccsi wrote:


  Your name: 
  Your age: 
  
In 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,


From "my" experience, I would suggest that you ALWAYS post back to the 
same URL. All forms I've seen that post to a different target have 
issues when validation fails and they suddenly need to go back to the 
original form-- they tend to implement weird and not so wonderful 
techniques to get back to that form while preserving the posted data in 
the session or something. If they try to go back at all... some just say 
fail and tell you to hit your browser's back button.


Leaving the action attribute empty should cause the browser to post back 
to the same URL without you needing to re-iterate it programmatically in 
the action attribute.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] From 24/7/2013 to 2013-07-24

2013-07-26 Thread Robert Cummings

On 13-07-26 05:33 PM, Jim Giner wrote:

On 7/26/2013 5:29 PM, Robert Cummings wrote:

And so it follows, that my solution, thus far, is the only solution
posted that actually meets the requirements. Why you think my solution
does not perform is beyond me since a simple run of the code would
output the correct answer (yes I did test)-- mine also presumes the
European ordering for all input with components separated by a slash.

Cheers,
Rob.

>

And my solution doesn't work?



I don't see any padding happening in your solution. Your solution produced:

2013-7-24

The required solution is:

2013-07-24

:)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] From 24/7/2013 to 2013-07-24

2013-07-26 Thread Robert Cummings

On 13-07-26 04:38 PM, jomali wrote:

On Fri, Jul 26, 2013 at 1:08 PM, Robert Cummings wrote:


On 13-07-26 11:42 AM, jomali wrote:


On Fri, Jul 26, 2013 at 5:18 AM, Karl-Arne Gjersøyen 
wrote:


  Below is something I try that ofcourse not work because of rsosort.

Here is my code:
---
$lagret_dato = $_POST['lagret_dato'];
  foreach($lagret_dato as $dag){

  $dag = explode("/", $dag);
 rsort($dag);
  $dag = implode("-", $dag);
  var_dump($dag);

What I want is a way to rewrite contents of a variable like this:

  From 24/7/2013 to 2013-07-24

Is there a way in PHP to do this?

Thank you very much.

Karl



$conv_date = str_replace('/', '-','24/7/2013');
echo date('Y-m-d', strtotime($conv_date));
Result: 2013-07-24



It would be better if you reformatted first since this is ambiguous when
you have the following date:

 6/7/2013




Here's a completely unambiguous solution:



Cheers,
Rob.


The original question was  about reformatting a European (Day/Month/Year)
date. Your solution does not address this problem. Mine assumes the
European date format explicitly.


Jomali,

Your solution is broken. The original poster requested the following:

>>>> What I want is a way to rewrite contents of a variable like this:
>>>>
>>>>   From 24/7/2013 to 2013-07-24

Your solution makes use of the strtodate(). A useful strategy EXCEPT (as 
you have already noted) the date follows the European formatting rules 
of dd/mm/ since the 24 as the first number makes that obvious. 
HOWEVER, you failed to realize the following (from the PHP online manual):


Dates in the m/d/y or d-m-y formats are disambiguated by looking
at the separator between the various components: if the separator
is a slash (/), then the American m/d/y is assumed; whereas if
the separator is a dash (-) or a dot (.), then the European d-m-y
format is assumed.

And so, as soon as an abiguous date arises, the solution will be 
incorrect because strtotime() will presume an American format due to the 
appearance of the slash instead of the hyphen. It is dangerous to rely 
on magical functions like strtotime() unless you completely understand 
how ambiguity is resolved.


Another solution that was posted only re-ordered the elements and you 
likely noticed that there is a single digit 7 in the source date and in 
the response date it has been 0 padded to conform to the standard 
-mm-dd date format. The other solution does not do this and so it is 
also incorrect.


And so it follows, that my solution, thus far, is the only solution 
posted that actually meets the requirements. Why you think my solution 
does not perform is beyond me since a simple run of the code would 
output the correct answer (yes I did test)-- mine also presumes the 
European ordering for all input with components separated by a slash.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] From 24/7/2013 to 2013-07-24

2013-07-26 Thread Robert Cummings

On 13-07-26 11:42 AM, jomali wrote:

On Fri, Jul 26, 2013 at 5:18 AM, Karl-Arne Gjersøyen wrote:


Below is something I try that ofcourse not work because of rsosort.
Here is my code:
---
$lagret_dato = $_POST['lagret_dato'];
 foreach($lagret_dato as $dag){

 $dag = explode("/", $dag);
rsort($dag);
 $dag = implode("-", $dag);
 var_dump($dag);

What I want is a way to rewrite contents of a variable like this:

 From 24/7/2013 to 2013-07-24

Is there a way in PHP to do this?

Thank you very much.

Karl



$conv_date = str_replace('/', '-','24/7/2013');
echo date('Y-m-d', strtotime($conv_date));
Result: 2013-07-24


It would be better if you reformatted first since this is ambiguous when 
you have the following date:


6/7/2013

Here's a completely unambiguous solution:

$paddy = function( $bit ){ return str_pad( $bit, 2, '0', 
STR_PAD_LEFT ); };
$new = implode( '-', array_map( $paddy, array_reverse( explode( 
'/', $old ) ) ) );


echo $new."\n";

?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] error_handler : unique "caller ID" ?

2012-11-13 Thread Robert Williams
On 11/13/12 11:20, "B. Aerts"  wrote:


>Having read access to a variable's address (like a C-pointer) would be
>perfect - but Google tells me you can't in PHP.

If you can restrict yourself to objects for the passed variables, you can
use spl_object_hash(). It does exactly what you need, but it only works
with objects. AFAIK, there's no equivalent for scalars or arrays.

<http://php.net/manual/en/function.spl-object-hash.php>


Regards,
Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Creating an Advanced Form

2012-11-02 Thread Robert Stone
Hi Jonathan,

Haven't used MySql for ages. More used to Oracle and PostgreSql.
Your table nmc_cd contains foreign keys pointing to nmc_category and 
nmc_publisher. Create a view containing all the data from those three tables 
using implicit joins as the data in table nmc_cd should NOT contain any 
"dangling" foreign keys. (You can always write a test routine to verify the 
cleaniless of your data). 

Thus you have a single query "SELECT * FROM my_nmc_view WHERE ($x IS NOT NULL 
AND $x = some colum name in the view) AND ($y IS NOT NULL . . . etc.
You can append an ORDER BY clause at the end reflecting the desired display 
sequence.
If all of your search criteria is null, then the select should return every row 
in the view.


I don't understand code such as  "  if($searchCDID=1){  ". Comparing for 
equality requires "==" or "===". How does this work if the user enters "345" 
for example?

Apropos other comments, this select statement ought to be in the controller (or 
action controller) depending on how your application is structured. 


Hope this helps.
Cheers,
Rob

[PHP] Free LAPP stack

2012-10-21 Thread Robert Stone
Hello,

There are several sites offering free LAMP stacks but does anybody know of a 
site that has free LAPP stacks available?

Please don't flame me for preferring PostgreSql.

It's to set-up a thin client application. Disk space required approx. 1.5Mb. I 
need it to facilitate testing. Any suggestions welcome.

TIA,

Robert


Re: [PHP] Re: PHP as Application Server

2012-09-26 Thread Robert Williams
On 9/26/12 10:18, "Matijn Woudt"  wrote:


>Writing scripts for an application server requires a much deeper
>understanding of threads and computer internals,so as a result it
>probably increases error rate.

Well... yes and no. PHP's architecture pretty much keeps you from having
to mess with thread management, but it does so by shifting the burden to a
higher level, either process management of multiple PHP processes or
thread management within the context of the HTTP server. If your
application is sufficiently simple, that shift may be enough to keep you
from having to worry about the problem. For most applications, however,
it's still a concern. In some ways, this can make things worse, simply
because PHP programmers tend to be oblivious of the potential problems,
whereas the typical C# or Java programmer has at least some awareness of
the various traps that await them.

As an example, I see PHP code *all the time* that is wide open to
concurrency issues with the database. Most code just assumes it's the only
code doing updates, but unless the server is set up to serialize requests,
that's an invalid assumption. Recently, more folks have started to address
this by using database transactions, but this is often done in ignorance
of what isolation level is being used and what the impact of that is upon
the code - which can just make things worse. Even when there is that
awareness, there are database concurrency issues with which transactions
can't help. (Of course, people who are aware of isolation levels also tend
to be aware of other concurrency issues.) The point is, if you have
multiple things running in parallel, whether that be threads within your
application or entirely separate physical servers running multiple copies
of your application, you have to deal with concurrency issues. It's a
necessary evil of parallel programming, and no mere technological solution
(language, database, whatever), now or in the future, can fully overcome
it. Well, maybe an AI engine somewhere in the chain, but that's about it,
and that's not coming anytime soon.

Incidentally, another advantage of PHP's share-nothing approach that
hasn't been mentioned is relatively easy scalability. In a shared pool
architecture, the easiest way to scale is typically vertically, that is,
adding RAM, faster drives, etc. This is fine, but you can only scale
vertically to a certain point, which you can usually hit pretty quickly.
With PHP's share-nothing approach, you can still scale vertically, but you
can almost as easily scale horizontally by adding more servers that each
run merrily in their own worlds, with the primary added coordination logic
being in the areas of communicating with the database and the data cache,
something the application should be designed with, anyway. In contrast,
the shared approach requires added logic, somewhere, to coordinate the
sharing amongst the pools of all that data that the application takes for
granted is always available at low cost.

Having said all that, there are many advantages and disadvantages to both
approaches. And honestly, I would love to have the option of a shared
approach with PHP, since that architecture simply works better as a
solution to certain problems. Assuming the shared-nothing model continues
on, it would make PHP that much more well-rounded. In that respect, the
added option isn't that different from the addition of OOP: we now have
the great ability to use procedural code where it makes sense, and to use
OOP code where it makes sense. Where neither is a perfect fit, you can
choose the one that creates the least personal pain. It's a wonderful
choice to have.


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Re: Programmers and developers needed

2012-09-19 Thread Robert Cummings

On 12-09-19 06:07 AM, Matijn Woudt wrote:

On Wed, Sep 19, 2012 at 11:53 AM, German Geek  wrote:

See below.

On 19 September 2012 04:45, Matijn Woudt  wrote:


On Tue, Sep 18, 2012 at 8:52 AM, agbo onyador  wrote:

The growing power of the internet and global networks.
(on the world’s politics, economies and even on daily life of ordinary
people) Programmers and developers needed:


Thanks



I still cannot figure out if this is a joke or if you're really
looking for world peace.. If you're serious, you might want to stop
and take a look at Newton's third law, I quote from wikipedia:
"When a first body exerts a force F1 on a second body, the second body
simultaneously exerts a force F2 = −F1 on the first body. This means
that F1 and F2 are equal in magnitude and opposite in direction.", or
simplified "To every action there is always an equal and opposite
reaction."
It fits also easily on humans, take one step into peace, and it will
have an effect in opposite direction elsewhere.

Also, why do you think you can make a better social network than the
already existing ones? Even the big internet giant Google can't seem
to make it's social network a big success, and you (without even an
concrete idea) can do that better?

You might as well just open a simple website with a 'Like' button and
ask everyone to like that page, so we end up with peace!:)



Seems like an interesting point. But who says that good and evil are always
cancelling each other out? To me good and evil depend on the point of view.
So, what's good for A could be good for B too but bad for C, and therefore
what's good for C is bad for both A and B? Not necessarily (following a
implies b is not equivalent to b implies a). It gets complicated very
quickly with more parties and we have more than 6 billion! One cannot really
say that an action is good or bad for everyone following your argument.
However, world peace, less pollution and equal or less diverse wealth would
be good for everyone, because of less crime and less risk of loosing
everything. Maybe it would trigger something bad at the other end of the
universe, but the universe is pretty big (so I've heard :-), so what do we
care? I vote for world peace in that sense.


Do I hear a vote for communism? That didn't really work out in the
past, so why would it now?


Not to say I'm all in for communism... but communism failed for the same 
reason capitalism is failing. Corruption!


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Re: Programmers and developers needed

2012-09-18 Thread Robert Cummings

On 12-09-18 02:38 PM, Jeff Burcher wrote:

-Original Message-
From: Robert Cummings [mailto:rob...@interjinn.com]
Sent: Tuesday, September 18, 2012 2:22 PM
To: Matijn Woudt
Cc: Daevid Vincent; PHP-General
Subject: Re: [PHP] Re: Programmers and developers needed

On 12-09-18 02:12 PM, Matijn Woudt wrote:

On Tue, Sep 18, 2012 at 8:02 PM, Daevid Vincent 

wrote:

-Original Message-
From: Matijn Woudt [mailto:tijn...@gmail.com]

You're missing the most important aspect of social networks..

Advertising.


Please tell me that is said sarcastically. Advertising is the cancer of the

internet. There was a time when there weren't ad banners, interstitials, pop-
ups, pop-unders, spam, and all the other bullshit you have to sift through on
a daily basis.




No,  I was not meant to be sarcastic. You might find advertising to be
the cancer of the internet, think again. The internet would be pretty
much dead without ads, or would you rather pay $0.01 per Google search
query? $0.01 for each e-mail send, $0.01 for each news article you
want to read, etc, etc? (or more related, $0.01 for each facebook
message you want to send/read?)

In the end, good advertising means success, take the drop of facebook
shares because of the investors being worried about facebooks'
advertising possibilities.


History suggests the internet would be here without advertising since it
originated without advertising, originally grew without advertising, and finally
evolved into this mixed blessing we have today. There's plenty of greatness
on the internet, there's also plenty of steaming piles of manure.

Cheers,
Rob.


Yeah, it grew out of government funding before advertising via educational

> institutions and the military. Would you rather have a free economy
> supported internet or a government controlled internet? Also, for those
> of us who are old enough to remember posting to text based bulletin 
boards,
> the influx of corporate money has greatly increased the 
infrastructure and
> functionality of the internet and has helped to make it a global 
phenomenon,
> which a government supported internet may have never become. Money 
makes all

things possible. If you don't think so, try building a server farm and

> hooking up to a trunk line without it. My two cents. Now, I'm broke.

You're making me wax philosophical... Money doesn't make all things 
possible. Time and energy make all things possible. Money is just a 
convenient placeholder for time and energy.


At any rate, you're making the assumption that advertising was a 
necessary ingredient. It was not... nor does it's absence guarantee a 
government controlled internet. You have a logical fallacy in your 
argument above, but I'm too lazy to look up which one (or which ones), 
but I can smell it (them) ;)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Re: Programmers and developers needed

2012-09-18 Thread Robert Cummings

On 12-09-18 02:12 PM, Matijn Woudt wrote:

On Tue, Sep 18, 2012 at 8:02 PM, Daevid Vincent  wrote:

-Original Message-
From: Matijn Woudt [mailto:tijn...@gmail.com]

You're missing the most important aspect of social networks.. Advertising.


Please tell me that is said sarcastically. Advertising is the cancer of the 
internet. There was a time when there weren't ad banners, interstitials, 
pop-ups, pop-unders, spam, and all the other bullshit you have to sift through 
on a daily basis.



No,  I was not meant to be sarcastic. You might find advertising to be
the cancer of the internet, think again. The internet would be pretty
much dead without ads, or would you rather pay $0.01 per Google search
query? $0.01 for each e-mail send, $0.01 for each news article you
want to read, etc, etc? (or more related, $0.01 for each facebook
message you want to send/read?)

In the end, good advertising means success, take the drop of facebook
shares because of the investors being worried about facebooks'
advertising possibilities.


History suggests the internet would be here without advertising since it 
originated without advertising, originally grew without advertising, and 
finally evolved into this mixed blessing we have today. There's plenty 
of greatness on the internet, there's also plenty of steaming piles of 
manure.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Programmers and developers needed

2012-09-14 Thread Robert Cummings

On 12-09-13 06:10 PM, Ashley Sheridan wrote:

On Thu, 2012-09-13 at 16:48 -0400, Tedd Sperling wrote:


On Sep 13, 2012, at 3:45 AM, agbo onyador  wrote:


Hello there! We are looking for programmers and developers to create a
world wide system. Your comments are welcome.


Wow!

I'm looking for world wide money.


tedd



Join the queue...


There's a queue? Bah humbug... I've been waiting for delivery all this time.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Programmers and developers needed

2012-09-13 Thread Robert Cummings

On 12-09-13 08:44 AM, Matijn Woudt wrote:

On Thu, Sep 13, 2012 at 2:12 PM, Steven Staples  wrote:

From: Tim Dunphy [mailto:bluethu...@gmail.com]
Sent: September 13, 2012 7:26 AM


We are looking for programmers and developers to create a world wide

system.

Is it bigger than a bread box?


Will it blend?



Sure, if you find a big enough blender ;)


There's a big one at the center of our galaxy :D

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] extract Occurrences AFTER ... and before "-30-"

2012-08-20 Thread Robert Cummings

On 12-08-21 01:11 AM, Robert Cummings wrote:

On 12-08-21 12:32 AM, John Taylor-Johnston wrote:




This is usually a first-year CS programming problem (word frequency
counts) complicated a little bit by needing to extract the text.
You've started off fine, stripping tags, converting to lower case,
you'll want to either convert or strip HTML entities as well, deciding
what you want to do with plurals and words like "you're", "Charlie's",
"it's", etc, also whether something like RFC822 is a word or not
(mixed letters and numbers).

When you've arranged all that, splitting on white space is trivial:

$words = preg_split('/[[:space:]]+/',$text);

and then you just run through the words building an associative array
by incrementing the count of each word as the key to the array:

foreach ($words as $word) {
   $freq[$word]++;
}

For output, you may want to sort the array:

ksort($freq);


That's awesome. Thanks!
Let me start with my first problem:

I want to extract All Occurrences of text AFTER "News Releases" and
before "-30-".

http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.html

How do I do that?

Yeah, I am still asking first year questions :)) Every project brings
new challenges.


You can use strpos() to find the location of "News Releases" then you
can again use strpos() to find the location of "-- 30 --" but you will
want to feed strpos() an offset for matching "-- 30 --" (specifically
the position found for "News Releases"). This ensures that you only
match on "-- 30 --" when it comes after "News Releases". Once you have
your beginning and start offsets you can use substr() to create a
substring of the interesting excerpt. Once you have the excerpt in hand
you can go back to JTJ's recommendation above.


Sorry... *YOU* are JTJ, but you trimmed the post including the 
responder's name (which you should leave intact when trimming). I defer 
(I think) to tamouse's recommendation above.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] extract Occurrences AFTER ... and before "-30-"

2012-08-20 Thread Robert Cummings

On 12-08-21 12:32 AM, John Taylor-Johnston wrote:




This is usually a first-year CS programming problem (word frequency
counts) complicated a little bit by needing to extract the text.
You've started off fine, stripping tags, converting to lower case,
you'll want to either convert or strip HTML entities as well, deciding
what you want to do with plurals and words like "you're", "Charlie's",
"it's", etc, also whether something like RFC822 is a word or not
(mixed letters and numbers).

When you've arranged all that, splitting on white space is trivial:

$words = preg_split('/[[:space:]]+/',$text);

and then you just run through the words building an associative array
by incrementing the count of each word as the key to the array:

foreach ($words as $word) {
  $freq[$word]++;
}

For output, you may want to sort the array:

ksort($freq);


That's awesome. Thanks!
Let me start with my first problem:

I want to extract All Occurrences of text AFTER "News Releases" and
before "-30-".

http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.html

How do I do that?

Yeah, I am still asking first year questions :)) Every project brings
new challenges.


You can use strpos() to find the location of "News Releases" then you 
can again use strpos() to find the location of "-- 30 --" but you will 
want to feed strpos() an offset for matching "-- 30 --" (specifically 
the position found for "News Releases"). This ensures that you only 
match on "-- 30 --" when it comes after "News Releases". Once you have 
your beginning and start offsets you can use substr() to create a 
substring of the interesting excerpt. Once you have the excerpt in hand 
you can go back to JTJ's recommendation above.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] APC expunge notices

2012-08-17 Thread Robert Cummings

On 12-08-17 05:22 PM, Nathan Nobbe wrote:

Hi everyone,

I'd like to see what other folks think about the idea of having APC provide
a E_WARNING or E_NOTICE when it has to expunge the cache.  Ideally, this
would include the amount of memory allocated in the error message.

The idea here is to provide system admins with information that

A. The cache had to be expunged
B. The amount of memory allocated when the cache had to be expunged

Right now, unless a close eye is kept, how is one to garner this
information.

Maybe, if the idea is interesting, it could be expanded to allow a user
defined callback method where custom behavior could be implemented.

Your feedback appreciated,


I like all of these ideas :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Need to have form protection techniques

2012-08-17 Thread Robert Cummings

On 12-08-17 10:59 AM, Al wrote:



On 8/17/2012 10:42 AM, Robert Cummings wrote:

On 12-08-17 10:15 AM, Tedd Sperling wrote:

On Aug 17, 2012, at 10:09 AM, Daniel Brown  wrote:


On Fri, Aug 17, 2012 at 12:05 AM, Ansry User 01  wrote:

I need to know the forms validity techniques for Php.


 This will probably take a while to absorb, so you may need to
revisit this page several times:

 http://oidk.net/php/know-the-forms-validity-techniques-for.php


No tedd, I'm sorry but the info in the link above is pretty much perfect.

Cheers,
Rob.


Looks to me as if it's been hacked.



I thought it was some intentional Friday entertainment!

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Need to have form protection techniques

2012-08-17 Thread Robert Cummings

On 12-08-17 11:14 AM, Tedd Sperling wrote:

On Aug 17, 2012, at 10:42 AM, Robert Cummings  wrote:

On Fri, Aug 17, 2012 at 12:05 AM, Ansry User 01  wrote:

I need to know the forms validity techniques for Php.


This will probably take a while to absorb, so you may need to
revisit this page several times:

http://oidk.net/php/know-the-forms-validity-techniques-for.php


No tedd, I'm sorry but the info in the link above is pretty much perfect.

Cheers,
Rob.


Oh, to be serious on this list on Fridays is lost cause.

I keep forgetting Fridays are like April 1.


:D

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Need to have form protection techniques

2012-08-17 Thread Robert Cummings

On 12-08-17 10:15 AM, Tedd Sperling wrote:

On Aug 17, 2012, at 10:09 AM, Daniel Brown  wrote:


On Fri, Aug 17, 2012 at 12:05 AM, Ansry User 01  wrote:

I need to know the forms validity techniques for Php.


This will probably take a while to absorb, so you may need to
revisit this page several times:

http://oidk.net/php/know-the-forms-validity-techniques-for.php


No tedd, I'm sorry but the info in the link above is pretty much perfect.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] PHP session variables

2012-08-15 Thread Robert Cummings

On 12-08-15 03:19 PM, Tedd Sperling wrote:

Rob:

Again thanks.

Sorry, I totally missed your point.

In my "defense" I commonly use the value returned from microtime() as a string and not as 
a float. The code that followed my "microtime( false );" demo broke the string and 
recombined it into a float. So, when you said:

Please see the current signature for microtime():

mixed microtime ([ bool $get_as_float = false ] )

I looked at that and said to myself, "Oh, I need to define it as 'false' " 
because I was using it as a sting. I completely overlooked your point that microtime() 
could return a float and thus no need to work with it as a string -- duh!

The demo is fixed (I think):

http://www.webbytedd.com/b/timed1/

Thanks,

tedd



I only pointed it out because I used to do exactly the same thing :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Reading class variable value always returns NULL

2012-08-14 Thread Robert Williams
I'm not real clear on what's happening. Are you saying that if you assign
values to the protected class members, and then immediately read them,
that they're null? So, there's code something like this:

class Foo {
   public function Something() {
  $this->foo = 1;

  //shows null instead of 1
  var_dump($this->foo);
   }

   protected $foo;
}



Is that right?


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] PHP session variables

2012-08-14 Thread Robert Cummings

On 12-08-14 10:41 AM, Tedd Sperling wrote:

On Aug 13, 2012, at 10:59 AM, Robert Cummings  wrote:


On 12-08-10 04:42 PM, Tedd Sperling wrote:

On Aug 10, 2012, at 1:21 PM, Ege Sertçetin  wrote:


Hi. My question will maybe out of topic, I'm sorry.
How can you know that one way will be much slower than other one? I mean, how 
can I learn which function is faster before I test it?


Ege:

No your question is on topic.

This question should be asked on the list, so I'll present Q:A instead of 
answering privately

http://www.webbytedd.com/b/timed1/

The code is there -- if you have questions, please post them to the list.


Ted,

Please see the current signature for microtime():

mixed microtime ([ bool $get_as_float = false ] )

The optional paramter was added in PHP 5.0.0. I think it's safe to update your 
habits :)

Cheers,
Rob.


Rob:

Fixed.

Thanks -- my habits are always in a state of being updated -- just ask my wife.


I'm not sure if you're making a joke, but your changes have no effect. 
You've merely explicitly stated the optional parameter's default value. 
What I had meant was to change the following:




To the following :)



Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Reading class variable value always returns NULL

2012-08-13 Thread Robert Cummings

On 12-08-12 08:32 AM, Reto Kaiser wrote:

Hi,

So I have this strange situation where I assign a classvariable a
value, but when I read the value it is NULL.

The class has one variable declared:
=
class A {
 private $_cookies;
}
=


That is a private instance variable NOT a class variable.

To declare a class variable you would do the following:




In a method of this class I assign this classvariable plus an
undeclared classvariable and a local variable the value 1:
=
$this->_cookies = 1;
$this->_cookies2 = 1;
$cookies3 = 1;
=

When I now read the values of those variables, the classvariables are
NULL while the local variable is 1:
=
$logEntry .= 'cookies: ' . var_export($this->_cookies, true) . PHP_EOL;
$logEntry .= 'cookies2: ' . var_export($this->_cookies2, true) . PHP_EOL;
$logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
=
cookies: NULL
cookies2: NULL
cookies3: 1
=

But when reading the whole object, the classvariables are 1:
=
$logEntry .= var_export($this, true) . PHP_EOL;
=
A::__set_state(array(
'_cookies' => 1,
'_cookies2' => 1,
))
=


This happens periodically on a busy webserver. It seems that when it
happens, all classvariables cannot be read anymore (return NULL).
After restarting Apache it does not happen anymore, just to happen
again after some minutes.

The system is current Debian Squeeze:
Linux: linux-image-2.6.32-5-amd64
Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
2012 07:31:32)
php -m: 
https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
php -i: 
https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

Does anyone have an idea what could cause this, or how to further debug?


I can't really speak to your specific problem (unless you're using two 
different instances of the class), just thought I'd clear up the 
difference between class variables and instance variables.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] PHP session variables

2012-08-13 Thread Robert Cummings

On 12-08-10 04:42 PM, Tedd Sperling wrote:

On Aug 10, 2012, at 1:21 PM, Ege Sertçetin  wrote:


Hi. My question will maybe out of topic, I'm sorry.
How can you know that one way will be much slower than other one? I mean, how 
can I learn which function is faster before I test it?


Ege:

No your question is on topic.

This question should be asked on the list, so I'll present Q:A instead of 
answering privately

http://www.webbytedd.com/b/timed1/

The code is there -- if you have questions, please post them to the list.


Ted,

Please see the current signature for microtime():

mixed microtime ([ bool $get_as_float = false ] )

The optional paramter was added in PHP 5.0.0. I think it's safe to 
update your habits :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Repeated New Object Requests

2012-08-13 Thread Robert Cummings

On 12-08-10 02:24 PM, Al wrote:


Off the subject a bit. What does PHP do with repeated new classes, e.g.
$mime = new Mail_mime   Are they simply ignored or are additional new instances
created. PHP won't let you duplicate function names.


Hi Al,

New isn't defining a class, it's a request for an instance of a defined 
class. Thus it will create a new instance over and over again for every 
time the new request is made. The equivalent to "won't let you duplicate 
function names" is "won't let you duplicate class names".


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Too many open files

2012-08-10 Thread Robert Cummings

On 12-08-10 02:49 AM, Matijn Woudt wrote:

On Fri, Aug 10, 2012 at 5:36 AM, Jim Lucas  wrote:

On 8/9/2012 5:01 PM, Al wrote:


Getting "Too many open files" error when processing an email batch
process.

I've looked extensively and can't find more than about 100 files that
could be open.  All my fetching is with get_file_contents();



Why not use fopen() and other related functions to open/grap/close your
batch of files?

You could replace a call like this:

$data = file_get_contents($filename);

with this:

if ( $fh = fopen($filename, 'r') ) {
   $data = fread($fh, filesize($filename));
   fclose($fh);
}

This should take care of your issue.

Jim Lucas


Why on earth would you want to reinvent the wheel? There's no point in
saying that fopen/fread/fclose is better, in fact, let me quote from
the manual page of file_get_contents:
"file_get_contents() is the preferred way to read the contents of a
file into a string. It will use memory mapping techniques if supported
by your OS to enhance performance."

If your solution would fix the problem (I doubt, but ok), then you
should report a bug to the PHP devs that file_get_contents is broken.


It wouldn't fix the problem. Performing fopen/fread/fclose in PHP is 
slower than the same process implemented in C in the PHP engine. Thus 
the file will spend more time in the open state thus exacerbating the 
problem.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Too many open files

2012-08-10 Thread Robert Cummings

On 12-08-09 08:01 PM, Al wrote:

Getting "Too many open files" error when processing an email batch process.

The batch size is actually rather small and the email text is small likewise.

I've looked extensively and can't find more than about 100 files that could be
open.  All my fetching is with get_file_contents();

I can't find a way to see what files could be open or what the limit is.

Site is on a shared server, cPanel.

   ^
THIS is probably your problem. Too many open files indicates that either 
the user OR the OS has reached its limit of allowed open file handles. 
Open files are those used by the OS and every user on the shared server. 
The setting can be changed but you'll need an administrator to increase 
the number of allowed open files. I suspect it's at the OS level if 
indeed you only have 100 files open (though you likely have more due to 
files opened for you by the OS or whatnot.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] XML/PHP web service

2012-08-08 Thread Robert Cummings

Hi Philip,

Tell them they can POST submissions to:

https://www.acme.com/xml-submission

Then tell them what fields are supported. Presumably you will support 
the following POST fields as a minimum (as if they were on a form):


username
password
xml

Your handler should also provide some feedback about whether the 
submission was successful of not. You can simply return output of a 1 
for success, a 0 for failure, or if you want to go whole hog you can 
output an XML response for which you can have much greater granularity 
for the response.


Cheers,
Rob.

On 12-08-08 06:57 PM, Phillip Baker wrote:

I was wondering how that would work and if it might be that simple.
How would I inform the client to hit the page (script)?

Blessed Be

Phillip

"In the Jim Crow South, for example, government failed and indeed refused
to protect blacks from extra-legal violence. Given our history, it's
stunning we fail to question those who would force upon us a total reliance
on the state for defense."
-- Robert J. Cottrol



On Wed, Aug 8, 2012 at 4:27 PM, Ashley Sheridan 
wrote:




Phillip Baker  wrote:


Greetings all,

I am looking for some options here.

I am in need of creating a service on our web server that will always
be
available and automated.
It will accept an XML file.

I will be checking to see if the XML file is valid and then passing it
on
to another server.
But I need to accept this file without using a submit form.
I have never done anything like this and looking for ideas.

I am using a lamp environment and looking for suggestions.

I am looking to set this up so that our vendors can set up scripts to
automatically post XML files to our servers.

Blessed Be

Phillip

"In the Jim Crow South, for example, government failed and indeed
refused
to protect blacks from extra-legal violence. Given our history, it's
stunning we fail to question those who would force upon us a total
reliance
on the state for defense."
-- Robert J. Cottrol


Just set up your php script as if it were accepting input from a form
submission. All you're doing is not showing the form. Imagine it like a
form set up on someone else's server with the action attribute pointing to
your script.

Ashley  Sheridan
http://www.ashleysheridan.co.uk

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.





--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Awkward time processing

2012-08-02 Thread Robert Williams
On 8/2/12 05:51, "Paul Halliday"  wrote:


>What I have is an array of values and timestamps:
>
>17 15:31
>16 15:32
>27 15:33
>14 15:34
>11 15:35
>
>now for a day I should have 1440 entries but there could be spotty
>results, no data from say 11:59 -> 13:00.
>What I need is to sum the values for each hour interval.

I may be misinterpreting what you're asking, but what about something like
this:

$times = array(
17 => '15:31',
16 => '15:32',
27 => '15:33',
14 => '15:34',
11 => '15:35',
27 => '16:33',
14 => '17:34',
11 => '11:35',
11 => '11:36',
);

$sums = array_fill(0, 24, 0);

foreach ($times as $value => $time) {
$sums[substr($time, 0, 2)] += (integer)$value;
}

print_r($sums);

This produces:


/usr/bin/php /Volumes/Dev/Sites/playground/play4.php
Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 11
    [12] => 0
[13] => 0
[14] => 0
[15] => 33
[16] => 27
[17] => 14
[18] => 0
[19] => 0
[20] => 0
[21] => 0
[22] => 0
[23] => 0
)

Process finished with exit code 0



--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] What do you call the end-user?

2012-07-20 Thread Robert Williams
On Jul 20, 2012, at 0:59, "Adam Nicholls"  wrote:

> Personally if I'm feeling a bit cheeky I'll go with "Muggle" - (thanks to J K 
> Rowling!) - people just don't appreciate the magic involved behind the scenes 
> in usability, infrastructure, application logic etc.

Wow. I really, really (, really) hate to admit it, but that actually fits 
extremely well. Damn.

--
Bob Williams

Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Entry point of an MVC framework

2012-07-12 Thread Robert Williams
On 7/12/12 14:44, "Daevid Vincent"  wrote:


>Personally I *hate* frameworks with a passion, but if you're going to use
>one, then why not just build with one that is already out there and well
>supported. http://www.phpframeworks.com/ to start with.

I wouldn't suggest most people try to build one to actually use, but that
said, building one for fun is an excellent way to hone your skills,
especially if you're one of those people who just can't seem to come up
with an idea for something better to build that would not only hone your
skills but also be useful to the world :-).


-Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Entry point of an MVC framework

2012-07-12 Thread Robert Williams
On 7/12/12 13:21, "Simon Dániel"  wrote:


>And I can't do it with the constructor of the inherited
>class, becouse this way I would overwrite the parent constructor.

Just call to the parent constructor from the child:

public function __construct() {
   parent::__construct();
   //do whatever
}

You can call it at any point, so you could do some setup stuff and then
call it, or call it and then do more setup stuff. Basically, you get to
augment the functionality of the parent constructor.

>And as far as I know, it is not a good practice to call a method outside
>of the class, becouse the concept of operation of the class should be
>hidden from the other parts of the application.

Calling methods of other classes is quite normal, and in fact, necessary
in most cases. The trick is that each class specifically decides which
methods it wants to allow outside code to call, which it wants only
children classes to call, and which should only be called internally.
Classes do this by declaring methods as public, protected, or private,
respectively.

<http://us.php.net/manual/en/language.oop5.visibility.php>

What you do want to aim for is a stable set of public methods, which means
that the names of existing methods and the parameters they take don¹t
change when you update the class. If you maintain this stability, then you
can make all the updates you want but not have to update any other code
using the classes. If you change the public methods (that is, change the
class API), then you'll break other code that's using those methods.

Another consideration, and one which you're also touching on, is that of
handling dependencies. If your class requires some other class to
function, you ideally should hand it an instance of the other class,
versus directly instantiating it. You can do this in a variety of ways,
but the most common are passing the object as a parameter to the class
constructor and passing it via an injection method. What you gain by doing
this is that if you want to change the behavior of the class (e.g., by
passing it an object that sends a message by SMS instead of the one it
previously used that sent messages by e-mail), it's a simple matter of
passing a different type of object that has the same public API. This also
makes testing quite a bit easier, since you can pass mock objects that
just pretend to do the functionality of the real ones, thus allowing you
to test the main class without worrying about whether all the secondary
classes upon which it relies will break anything. When you're ready to
learn more about this, do a Google search for "php (inversion of control)".

-Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] How does this code work?

2012-07-03 Thread Robert Williams
On Jul 2, 2012, at 22:15, "Jim Lucas"  wrote:

> I think you missed something here...
>
> The above function uses strtr() not strstr()

Wow. I knew there had to be a simple, logical explanation (there was), that it 
would likely be one of those stupid things that I'd spot in two seconds the 
next morning (it was). That didn't stop me, however, from spending the last few 
hours hashing it over in the back of my mind, trying to figure out what magical 
power could make strstr() return content that is not in the haystack.

I feel like an idiot now, but at the same time, I am greatly relieved that all 
is right with the world, that the logic I've grown so accustomed to in thirty 
years of programming had not gone to voodoo. Thank you for that :-).

Hmm, I wonder if those thirty years are having a different sort of impact on 
me, in the form of decaying eyesight

--
Bob Williams

Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



[PHP] How does this code work?

2012-07-02 Thread Robert Williams
I found this code in a user comment in the PHP docs for htmlentities():

$v)
$trans[$k]= "&#".ord($k).";";

return strtr($string, $trans);
}

?>

It seems to work. For instance, this (assuming UTF-8 encoding):

echo xml_character_encode('Château');
echo "\n";
echo xml_character_encode('Ch&teau');

Yields this:

Château
Ch&teau

My question is, *how* does it work? It makes sense right up to the return 
statement. According to the docs for strstr(), when a non-string is passed in 
as the needle, it's, "converted to an integer and applied as the ordinal value 
of a character." First, an array-to-int conversion is undefined, though it 
seems to produce 1 on my copy of PHP. Now, I'm not quite sure how to interpret 
the last part of that statement from the docs, but I take it that the ultimate 
value supplied to strstr() is going to be either '1' (the character value of 
the integer value of the array) or '49' (the ordinal value of the character 
'1'). Whatever, neither one makes sense to look for in the haystack, so I'm 
obviously missing something.

Perhaps it's just late-Monday slowness on my part, but what's going on here? I 
have no intention of using this code, but I'd sure like to understand how it 
works!


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).


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

2012-06-30 Thread Robert Williams
Zend Server includes a job queue.



It supports queuing up jobs directly in the UI or via a PHP API, and it 
includes a variety of scheduling and load management options.

--
Bob Williams

Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] why is (intval('444-44444') == '444-44444') EQUAL??!

2012-06-21 Thread Robert Cummings



On 12-06-21 10:27 PM, Daevid Vincent wrote:

Huh? Why is this equal??!

php>  $id = '444-4';

php>  var_dump($id, intval($id));
string(9) "444-4"
int(444)

php>  if (intval($id) == $id) echo 'equal'; else echo 'not equal';
equal

or in other words:

php>  if (intval('444-4') == '444-4') echo 'equal'; else
echo 'not equal';
equal

I would expect PHP to be evaluating string "444-4" against integer "444"
(or string either way)

however, just for giggles, using === works...

php>  if ($id === intval($id)) echo 'equal'; else echo 'not equal';
not equal


Using === will always fail because on the left you have a string and on 
the right you have an integer which fails exact comparison based on 
datatype mismatch.


When comparing a string to an integer using == PHP performs type 
juggling and converts the string to an integer first.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] help with preg_match

2012-06-03 Thread Robert Williams
On Jun 3, 2012, at 17:28, "Chris Purves"  wrote:

> I know that the text ends 'end', but I don't know what the Something,
> something is.  I am using preg_match as follows:
>
> preg_match('/[^>]*end/',$curl_response,$matches);
>
> I want to match 'end' and everything before it that is not '>'.

You need to match something at the beginning. Try this:

preg_match('/>([^>]*end)/', $curl_response, $matches);

Assuming a match, you can then look to $matches[1] for your content.


--
Bob Williams

Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Function size

2012-05-29 Thread Robert Cummings

On 12-05-29 07:17 AM, Stuart Dallas wrote:
>

I wasn't going to respond to this thread because I think it's a largely

> ridiculous topic, but some of the responses have scared me. Sir Cummings
> (hopefully) sarcastic response about using a 5px font size demonstrated
> how daft it is to base function size on how much code you can see on the
> screen at once.

Guilty as charged ;)

One time I was helping a friend of mine do his Java homework at Cornell 
and when he got the assignment back he scored 24 out of 25 and I was 
like "What?!". The marker subtracted a point for a function that spanned 
more than one printed page. What a dork! I guess he didn't like my brace 
style since if I'd used a less vertically consumptive style then it 
would have printed cleanly on one page *lol*.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Function size

2012-05-23 Thread Robert Cummings

On 12-05-23 12:15 PM, Tedd Sperling wrote:


On May 23, 2012, at 11:49 AM, shiplu wrote:

On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
When number of lines becomes the criteria of function size? Wouldn't it depends 
on the task the function is doing?


You missed the point.

Of course, the difficulty of the task of a specific function will directly 
contribute to the number of lines of code for that function, but that's not 
what I was talking about.

What I was talking about was that what we can grasp in one view, we can 
understand better. If the code lies outside of our view, then we understand it 
less. I can support this claim with numerous articles/books/studies of human 
visual limits vs short-term memory. I am only bringing this forward for us to 
consider in our writing code. If we know why we do things, then we can better 
understand what we do.


That's why I code in 5px font. On my huge monitor I sometimes find the 
code is shaped like a tiger, or a dragon, I swear I even saw Piccolo. It 
really does help to see the big picture :B


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-04 Thread Robert Cummings

On 12-04-04 04:40 PM, Lester Caine wrote:

( forget email addres :( )
Robert Cummings wrote:

On 12-04-04 02:42 PM, Lester Caine wrote:

Tedd Sperling wrote:

Let me start a religious war -- should one end their scripts with "?>" or not?


Just as long as no one proposes making leaving out compulsory ;)

While I can sort of understand the logic when the file is all php and just has
an opening

These kinds of files don't generally have issues with trailing whitespace though
:) I certainly close the tags in these cases.


I'm not alone then :)
But I prefer EVERY tag to be closed ... perhaps that would change if the IDE's
faked a closing tag when it's missing so they don't get flagged as an error :(


IDE? Get off my lawn!!

;)

I develop in JOE.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-04 Thread Robert Cummings

On 12-04-04 02:42 PM, Lester Caine wrote:

Tedd Sperling wrote:

Let me start a religious war -- should one end their scripts with "?>" or not?


Just as long as no one proposes making leaving out compulsory ;)

While I can sort of understand the logic when the file is all php and just has
an opening

These kinds of files don't generally have issues with trailing 
whitespace though :) I certainly close the tags in these cases.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-03 Thread Robert Cummings

On 12-04-04 01: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.


From an age long gone when I asked the exact same question and Big 
Daddy answered:


http://marc.info/?l=php-internals&m=106896382030183&w=2

Then again a couple of years later:

http://marc.info/?l=php-internals&m=112537775409619&w=2

And in the manual itself (see the note):

http://ca.php.net/basic-syntax.instruction-separation

Zend Framework and Drupal are examples of large codebases that have 
adopted the omission as a best practice.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-03 Thread Robert Cummings

On 12-04-03 11:39 PM, Donovan Brooke wrote:

Stuart Dallas wrote:
[snip]

Usually when setting headers after such a script has been included when output 
buffering is turned off. Personally I never put the closing ?>   in if it's at 
the end of the file because it's unnecessary and can cause issues if it's present, 
but it's personal preference more than anything else.

Ultimately you have to consider that there's a reason it's optional - things like that 
don't generally happen by accident. I remember Rasmus commenting on this style issue a 
few years back so a search of the archives should find an "official" position.

-Stuart



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?


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-03 Thread Robert Cummings


On 12-04-03 05:29 PM, Tedd Sperling wrote:

Hi gang:

Let me start a religious war -- should one end their scripts with "?>" or not?

After years of never having a problem with ending any of my scripts with "?>", I 
found that several students in my class had scripts that did not produce the desired result even 
after they were given the scripts via highlight_file(") to cut and paste.

As it turned out, several students copy/pasted the script with an addition whitespace after 
the ending "?>" and as such the scripts did not run as expected. You see, the 
scripts created image but apparently the image delivery method objected to the additional 
whitespace.

Does anyone have more examples of where scripts will fail IF they end with "?>  
" (note the additional space)?


It's standard practice to NOT include the closing ?> on anything 
remotely resembling a class or lib source file. As has been mentioned on 
this list and originally on PHP internals on several occasions, the 
optionality of the closing tag is intentional :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-04-02 Thread Robert Cummings

On 12-04-02 04:36 PM, Jay Blanchard wrote:

[snip]

function getTiersJson( $company )
{
$tiers = getTiers( $company );
$json = JSON_encode( $tiers );
}

$tiersJson = getTiersJson( 1 );

?>

This will output JSON with the following structure:


[/snip]

OK, now I know I am being dense - but don't I have to add return $json; to 
getTiersJson() ?


yeah, *lol* in my testing I had a print_r() in the getTiersJson() so 
didn't notice I wasn't returning since I didn't do anything with the 
captured value (null without a proper return).


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-30 Thread Robert Cummings

On 12-03-27 11:11 AM, Jay Blanchard wrote:

[snip]On 3/27/2012 12:21 AM, Robert Cummings wrote:

>> [-- SNIP --]

Essentially, entries at the root and entries for the children are just
auto indexed array items but the actual entries in those arrays retain
the associative index structure for retrieval of the specific
information. let me know and I can probably whip you up something.


Robert that looks correct. Here is an example of the JSON that the guy
provided for me -

   var json = {
  id: "node02",
  name: "0.2",
  data: {},
  children: [{
  id: "node13",
  name: "1.3",
  data: {},
  children: [{
  id: "node24",
  name: "2.4",
  data: {},
  children: [{
  id: "node35",
  name: "3.5",
  data: {},
  children: [{
  id: "node46",
  name: "4.6",
  data: {},
  children: []
  }]
  }, {
  id: "node37",
  name: "3.7",
  data: {},
  children: [{
  id: "node48",
  name: "4.8",
  data: {},
  children: []
  }, {
  id: "node49",
  name: "4.9",
  data: {},
  children: []
  }, {
  id: "node410",
  name: "4.10",
  data: {},
  children: []
  }, {
  id: "node411",
  name: "4.11",
  data: {},
  children: []
  }]
  },
Of course he properly closes up the JSON. I inserted id's (just an
auto-incrementing number) and the data portion where needed. The name:
is the part that has been the result of what you did before.


Here's the code... I did a bit of shuffling and actually tested against 
a test db table:




And here's the code:

getConnectionRef();

$query =
"SELECT DISTINCT "
   ."   * "
   ."FROM "
   ."   tiers "
   ."WHERE "
   ."   company = {$company} ";

$root = array();
if( $db->query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus = &$root;
for( $i = 1; $i <= 14; $i++ )
{
$name = trim( $row['tier'.$i] );
if( $name === '' )
{
break;
}

if( !isset( $focus[$name] ) )
{
$focus[$name] = array
(
'name' => $name,
'children' => array(),
);
}

$focus = &$focus[$name]['children'];
}
}
}

$wrapper = array
(
'children' => &$root
);

postProcessTiers( $wrapper );

return $root;
}

function postProcessTiers( &$root )
{
$root['children'] = array_values( $root['children'] );

foreach( array_keys( $root['children'] ) as $index )
{
postProcessTiers( $root['children'][$index] );
}
}

function getTiersJson( $company )
{
$tiers = getTiers( $company );
$json = JSON_encode( $tiers );
}

$tiersJson = getTiersJson( 1 );

?>

This will output JSON with the following structure:



PHP is smart enough to detect an array that only has consecutive integer 
keys and create the appropriate JavaScript array object. So we don't 
have to do any special processing of the JSON after we've post processed 
the tier structure itself.


Cheers,
Rob
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Need PHP & Web Developer in So Cal

2012-03-28 Thread Robert Cummings

On 12-03-28 12:20 PM, Paul Scott wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 28/03/2012 18:04, Michael Frankel wrote:

Hi -

I am looking for a reliable, experienced PHP / Web developer or
development company to assist me with one of my long-time clients.
I need someone who has experience with all the following
technologies working in a hosted environment:


[snip]


- Can be responsive to client emergencies - NOTE: this is the MOST
important quality


Translates to "we will be phoning you at 2am and you are expected to
be there with a smile on your face for the client"

Am I right? Yeah, I know I am... ;)


I always have a smile on my face... yeah, I'm smiling right now!! :D

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings

On 12-03-26 07:05 PM, Jay Blanchard wrote:

[snip]
On Mar 26, 2012, at 5:58 PM, Robert Cummings wrote:


On 12-03-26 06:52 PM, Jay Blanchard wrote:

[snip]

Did you end up with a satisfactory output? It's not overly difficult to 
generate an array instead of an object.

[/snip]

I did for all but this one instance. Are you saying that it would be easy to 
make of the children arrays? I thought they were already - am I missing 
something?


They are arrays... but JSON_encode is creating objects. You can create arrays 
by traversing the array structure recursively and outputing your own JavaScript 
code to build a JavaScript array. I don't know if that would serve the purpose, 
but you would end up with an array.

[/snip]

I'm listening - so could this be added to the code that you just wrote? Or do I 
need to recurse the output from json_encode()?


I think you need two things... the recursive post processor that removes 
the string indexes for the children. And then a function that creates a 
JavaScript array expression from an object or array. The question I have 
for you... is given the following array structure that might be 
generated from my previous code:


 array
(
'name' => 'exec-001',
'children' => array
(
'sub-exec-011' => array
(
'name' => 'sub-exec-011',
'children' => array
(
'sub-sub-exec-111' => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
'sub-sub-exec-112' => array
(
'name' => 'sub-sub-exec-112',
'children' => array()
)
)
),
'sub-exec-012' => array
(
'name' => 'sub-exec-012',
'children' => array
(
'sub-sub-exec-121' => array
(
'name' => 'sub-sub-exec-121',
'children' => array()
),
'sub-sub-exec-122' => array
(
'name' => 'sub-sub-exec-122',
'children' => array()
)
)
)
)
),
'exec-002' => array
(
'name' => 'exec-002',
'children' => array
(
'sub-exec-021' => array
(
'name' => 'sub-exec-021',
'children' => array
(
'sub-sub-exec-211' => array
(
'name' => 'sub-sub-exec-211',
'children' => array()
),
'sub-sub-exec-212' => array
(
'name' => 'sub-sub-exec-212',
'children' => array()
)
)
),
'sub-exec-022' => array
(
'name' => 'sub-exec-022',
'children' => array
(
'sub-sub-exec-221' => array
(
'name' => 'sub-sub-exec-221',
'children' => array()
),
'sub-sub-exec-222' => array
(
'name' => 'sub-sub-exec-222',
'children' => array()
)
)
)
)
)
);

?>

On first blush, I think you want the following structure (from your 
recent posts):


 array
(
'name' => 'exec-001',
'children' => array
(
0 => array
(
'name' => 'sub-exec-011',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
1 => array
 

Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings

On 12-03-26 06:52 PM, Jay Blanchard wrote:

[snip]

Did you end up with a satisfactory output? It's not overly difficult to 
generate an array instead of an object.

[/snip]

I did for all but this one instance. Are you saying that it would be easy to 
make of the children arrays? I thought they were already - am I missing 
something?


They are arrays... but JSON_encode is creating objects. You can create 
arrays by traversing the array structure recursively and outputing your 
own JavaScript code to build a JavaScript array. I don't know if that 
would serve the purpose, but you would end up with an array.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings

On 12-03-26 05:14 PM, Jay Blanchard wrote:

[snip]

*lol* No worries... it's all about solving problems :)

[/snip]

the other folks who needed to consume the JSON have all done so successfully 
today - just this one. The guy who runs it was plenty arrogant when I discussed 
with him. He is the one who wanted me to remove the extra array name. I cooked 
up some regex to do that but then all of the opening/closing curlies were out 
of whack. If I had kept going it would have been maddening. I told him he 
needed to fix his JSON parsing. He said I needed to add the square brackets. 
Programmer stand-off.


Did you end up with a satisfactory output? It's not overly difficult to 
generate an array instead of an object.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-26 Thread Robert Cummings

On 12-03-26 02:12 PM, Jay Blanchard wrote:

[snip]
This is one of "those" projects. It is apparently going to be trying every step 
of the way.
[/snip]

I was proven right this morning after all of Robert's good work and what I had 
added to make this work.  It turns out that the one service who was anxious to 
consume the JSON output expects that the JSON be a certain format. When I run 
their format through jslint it does not validate unless I add quotes around the 
name portion of the name:value pairs. In addition they use (perfectly valid) 
square brackets around the children groups that the output from json_encode() 
does not contain.

I am ready to take a loss on this one but I really didn't lose - Robert gave me 
a great way to retrieve the data with one query and create valid JSON from it. 
Thanks again Robert!


*lol* No worries... it's all about solving problems :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings

On 12-03-24 04:11 PM, Jay Blanchard wrote:

[snip]

One more little tweak may be required. The JSON looks like this

{"Executives and Management":{"name":"Executives and Management","children":{

The first part {"Executives and Management": needs to be removed. I think I 
know what to do.

[/snip]

It has become painfully obvious that I do not know what to do. Ready to call it 
a day. Besides I just burned my finger setting up the smoker for the ribs.


It's a necessary part of building the structure. It can be removed but 
only as a post process. Why does it have to be removed? You can loop 
through the structure in JavaScript without paying heed to the key's value.


If it absolutely must go... you need to recurse through the final 
structure replacing each "children" entry with the results of passing it 
through array_values().


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings

On 12-03-24 01:09 PM, Jay Blanchard wrote:

[snip]The crux of it is:


$focus =&$focus[$name];
[/snip]


It works as I expect so far. All I have to do is figure out how to make the 
element a name: element in the JSON. for instance an element would look like 
this

{
name: "Bob",
children: []
}

So the PHP array would have to look like this -

$json = array (
name =>  "Bob",
children =>  array (
name =>  "Angie"
)
)

and so on. This is for one of the services that will consume the JSON.


A little tweak here... a little tweak there:

query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus = &$root;
for( $i = 1; $i <= 14; $i++ )
{
$name = $row['tier'.$i];

if( !isset( $focus[$name] ) )
{
$focus[$name] = array
(
'name' => $name,
'children' => array(),
);
}

$focus = &$focus[$name]['children'];
}
}
}

$json = JSON_encode( $root );
?>
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-24 Thread Robert Cummings

On 12-03-24 08:41 AM, Jay Blanchard wrote:


On Mar 23, 2012, at 11:24 PM, Robert Cummings wrote:


On 12-03-23 05:41 PM, Jay Blanchard wrote:

[-- DELETED GARBAGE --]  :)


I just realized... I've been stuck in a thinking rut. I latched onto one 
solution that works well in some case but didn't fully examine the nuances of 
your own scenario. Given the way you are creating your hierarchy you will 
ultimately retrieve all rows. As such the following simple solution will do 
what you need:

query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus =&$root;
for( $i = 1; $i<= 14; $i++ )
{
$name = $row['tier'.$i];

if( !isset( $focus[$name] ) )
{
$focus[$name] = array();
}

$focus =&$focus[$name];
}
}
}

$json = JSON_encode( $root );

?>


The crux of it is:

$focus = &$focus[$name];

because it facilitates moving deeper and deeper into the array.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] foreach weirdness

2012-03-24 Thread Robert Cummings

On 12-03-24 11:15 AM, Al wrote:



On 3/23/2012 10:11 PM, Robert Cummings wrote:

On 12-03-23 06:30 PM, Simon Schick wrote:

2012/3/23 Robert Cummings


On 12-03-23 11:16 AM, Arno Kuhl wrote:



it still does not produce the correct result:
0 1 3 6 10 15 21
0 1 3 6 10 15 15



This looks like a bug... the last row should be the same. What version of
PHP are you using? Have you checked the online bug reports?




Hi, Robert

Does not seem like a bug to me ...
http://schlueters.de/blog/archives/141-References-and-foreach.html

What you should do to get the expected result:
Unset the variable after you don't need this reference any longer.


Ah yes... that clued me in. I disagree with the article's generalization with
respect to references since references accomplish some things that cannot be
accomplished otherwise, but even I missed the fact that the second loop was
using a variable that was a reference to the last element of the array as
created in the first loop *lol*. The user's very act of checking their results
was confounding the result... I love it :)

Cheers,
Rob.


Re, your "...that cannot be accomplished otherwise,..." Can you provide some
examples?  The only ones I've found are when using create_function() and the
arguments for callback functions. I can't even remember or find in my code an
example of my foreach()loops needed it. Seems, I recall earlier versions of PHP
[<4? ]required references for variables.


After I submitted "...that cannot be accomplished otherwise,...", I 
realized it was a patently false statement (a turing machine is a turing 
machine :). The intent of the statement though was to indicate the 
greater difficulty in achieving something relatively simple with 
references. See the other thread "Thinking out loud - continuation". My 
post dated 2012-03-24 00:24 shows a process that is cumbersome and 
inefficient to implement in another fashion. References are like 
pointers... very powerful but with cautions for the unwary.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 05:41 PM, Jay Blanchard wrote:

[-- DELETED GARBAGE --]  :)


I just realized... I've been stuck in a thinking rut. I latched onto one 
solution that works well in some case but didn't fully examine the 
nuances of your own scenario. Given the way you are creating your 
hierarchy you will ultimately retrieve all rows. As such the following 
simple solution will do what you need:


query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus = &$root;
for( $i = 1; $i <= 14; $i++ )
{
$name = $row['tier'.$i];

if( !isset( $focus[$name] ) )
{
$focus[$name] = array();
}

$focus = &$focus[$name];
}
}
}

$json = JSON_encode( $root );

?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 05:26 PM, Jay Blanchard wrote:

[snip]

$item['children'] should be an array, somehow a string has been assigned :/

[/snip]

Yep. I am trying to figure that out now. I'm sure it is something really small.

[/snip]

I have been hammering away at it for a while now and still cannot find the 
issue. I'll push away for a while and come back to it. Robert I owe you so many 
thinks for getting me this far and opening me up to making this more efficient. 
I just have to push on through and get to the point where  the JSON can be 
created and consumed. If any light bulb goes on over your head would you let me 
know. I have tried everything that I know works to keep this from being a 
string - I am just missing something.


Hi Jay,

Did you send me a sample dump for your table :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] foreach weirdness

2012-03-23 Thread Robert Cummings

On 12-03-23 06:30 PM, Simon Schick wrote:

2012/3/23 Robert Cummings


On 12-03-23 11:16 AM, Arno Kuhl wrote:



it still does not produce the correct result:
0 1 3 6 10 15 21
0 1 3 6 10 15 15



This looks like a bug... the last row should be the same. What version of
PHP are you using? Have you checked the online bug reports?




Hi, Robert

Does not seem like a bug to me ...
http://schlueters.de/blog/archives/141-References-and-foreach.html

What you should do to get the expected result:
Unset the variable after you don't need this reference any longer.


Ah yes... that clued me in. I disagree with the article's generalization 
with respect to references since references accomplish some things that 
cannot be accomplished otherwise, but even I missed the fact that the 
second loop was using a variable that was a reference to the last 
element of the array as created in the first loop *lol*. The user's very 
act of checking their results was confounding the result... I love it :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 03:52 PM, Jay Blanchard wrote:

[snip]
SELECT DISTINCT `TIER3DATA` AS id, `TIER2DATA` AS parentId FROM 
`POSITION_SETUP` WHERE `COMPANY_ID` = '3' AND `TIER2DATA` IN ('Executives and 
Management','Professionals','Technicians','Craft 
Workers-Skilled','Operatives','Contractor','Sales Workers','Laborers and 
Helpers','Admin Support')

and it is empty.

[/snip]

I figured out part of the problem - the for loop starts at tier2 instead of 
tier1


It's meant to since outside the loop we address tier 1 when we generate 
the root and first set of parents (These have no parent ID so they are a 
special case).



Once I made that change I get the following error:

Fatal error: Cannot use string offset as an array in 
/home/orcadept/public_html/poschart/json_chart.php on line 139

Line 139 is $item['children'][$id] =&$child;


$item['children'] should be an array, somehow a string has been assigned :/

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 03:28 PM, Jay Blanchard wrote:


On Mar 23, 2012, at 2:25 PM, Robert Cummings wrote:


On 12-03-23 03:17 PM, Jay Blanchard wrote:

[snip]

$json = JSON_encode( $root );

[/snip]

Update on my test. This works perfectly Robert - thank you very much! But there 
is one small problem that I am trouble-shooting: it only goes one layer and 
doesn't progress any further. I suspect it is on this section of code that I am 
going to add some stuff to to see what is happening.

if( !($parents =&$children) ){
break;
}


I didn't actually test it... if you have trouble figuring out the problem feel 
free to send me a copy of your table (in private) and I'll debug :)


I had it backwards. Both arrays are empty and the break should not occur 
because they are equal to each other. Let me send you a portion of the table 
Robert.


No, I'm performing assignment... intentionally. Parent's becomes the 
previous children to move down a level. The following:


if( !($parents = &$children) )

performs assignment and an empty array check in one statement.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] foreach weirdness

2012-03-23 Thread Robert Cummings

On 12-03-23 02:04 PM, Arno Kuhl wrote:

Hi Rob

I'm using php 5.3.5. What result do you get when you run this code?
I haven't checked any bug reports, I'll google to see where I would do that.

Your code gets round the problem, but I was specifically referring to the use 
of foreach with its unexpected side-effects.


I know... but when I first started doing things like what you tried to 
do, there were no references for foreach values and so I've just 
naturally been in the habit of explicitly accessing the values in the 
array by index. Apparently that will serve me well since my stuff won't 
blow up with this bug ;)



There are a few different designs like look-ahead where it seemed the obvious 
way to go. I know I've used this type of foreach coding in the past, and have 
this nagging feeling there's a whole bunch of code just waiting to explode. I 
always just assumed it worked because it's pretty simple. I'd previously been 
caught out forgetting the assign by reference in the foreach loop that modified 
the array but I always caught it long before it went live, but I never 
considered having to also use assign by reference in subsequent foreach loops 
because it so obviously wasn't necessary. Now I'm searching through my scripts 
to see if there are any potential problems caused by this (already found one), 
and wondering what else I've done where I no longer have access to the sources.

BTW I'm told on another forum this issue has been discussed multiple times on 
this mailing list - did I miss it? Was there a resolution?


I must have missed it too... but then I've not been very active in the 
past year or so :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 03:22 PM, Jay Blanchard wrote:



[snip]

   $json = JSON_encode( $root );

[/snip]

Update on my test. This works perfectly Robert - thank you very much! But there 
is one small problem that I am trouble-shooting: it only goes one layer and 
doesn't progress any further. I suspect it is on this section of code that I am 
going to add some stuff to to see what is happening.

if( !($parents =&$children) ){
   break;
   }


It would appear that both arrays are empty on the next cycle through so the 
break occurs.


Did you get any results form the database on the second run through the 
query loop?


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 03:17 PM, Jay Blanchard wrote:

[snip]

$json = JSON_encode( $root );

[/snip]

Update on my test. This works perfectly Robert - thank you very much! But there 
is one small problem that I am trouble-shooting: it only goes one layer and 
doesn't progress any further. I suspect it is on this section of code that I am 
going to add some stuff to to see what is happening.

if( !($parents =&$children) ){
break;
}


I didn't actually test it... if you have trouble figuring out the 
problem feel free to send me a copy of your table (in private) and I'll 
debug :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-23 Thread Robert Cummings

On 12-03-23 02:08 PM, Jay Blanchard wrote:

[snip]

Your data structure doesn't appear to be very ummm normalized... Nonetheless, 
the following should do it:

[/snip]

You're absolutely correct. Unfortunately I am not the designer and cannot 
really do anything about it. I just have to work with what I have. Thank you 
very much for this - I will test it out this afternoon and let you know how it 
all goes.



I figured it was something you had been given... just thought I'd point 
out the obvious >:D


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] foreach weirdness

2012-03-23 Thread Robert Cummings

On 12-03-23 11:16 AM, Arno Kuhl wrote:

The following snippet is copied from the php manual:
foreach ($arr as $key =>  $value) {
echo "Key: $key; Value: $value\n";
}

I've always used the foreach loop that way.
But recently I started hitting some really odd problems.

See this following example that illustrates the problem:
$array = array(0, 1, 2, 3, 4, 5, 6);
foreach ($array as $index=>$value) {
if ( ($index+1)<  count($array) ) {
$array[$index+1] += $value;
}
echo $value." ";
}
echo "";
foreach ($array as $index=>$value) {
echo $value." ";
}

You'd expect the output to be:
0 1 3 6 10 15 21
0 1 3 6 10 15 21

But it's actually:
0 1 2 3 4 5 6
0 1 3 5 7 9 11


This is what I would expect since the value is a copy. As such, one 
would expect it to be the value before you made modifications to the array.



If you assign the $value by reference in the first loop as someone pointed
out (and confirmed by the manual: "As of PHP 5, you can easily modify
array's elements by preceding $value with&. This will assign reference
instead of copying the value")

$array = array(0, 1, 2, 3, 4, 5, 6);
foreach ($array as $index=>&$value) {//<- assign $value by reference
if ( ($index+1)<  count($array) ) {
$array[$index+1] += $value;
}
echo $value." ";
}
echo "";
foreach ($array as $index=>$value) {
echo $value." ";
}

it still does not produce the correct result:
0 1 3 6 10 15 21
0 1 3 6 10 15 15


This looks like a bug... the last row should be the same. What version 
of PHP are you using? Have you checked the online bug reports?



If I watch the $array in a debugger I see odd behaviour for the last element
$array[6] when stepping through the second foreach loop.
Just before entering the second loop $array[6] == 21 which is correct.
When I move to the next line (echo $value." ";)  $array[6] changes to 0 !!
As I step through the second loop $array[6] keeps on changing for each
iteration, with the following values:
0, 1, 3, 6, 10, 15, 15
And once I've left the second loop $array[6] is permanently changed from 21
to 15, even though there's no code in the second loop to change $array[6].
So what's going on here?

I confirm this by echoing $array[6] in each iteration in the second loop:
$array = array(0, 1, 2, 3, 4, 5, 6);
foreach ($array as $index=>&$value) {
if ( ($index+1)<  count($array) ) {
$array[$index+1] += $value;
}
echo $value." ";
}
echo "";
foreach ($array as $index=>$value) {
echo $array[6]." ";
}
echo "";
echo $array[6];

the result is:
0 1 3 6 10 15 21
0 1 3 6 10 15 15
15

Note that $array[6] is still 15 even after completing the second foreach
loop.
If you break out of the second loop then $array[6] will be at whatever value
it was at the time you break out (ouch!)

If you assign the $value by reference in the second loop as well:
$array = array(0, 1, 2, 3, 4, 5, 6);
foreach ($array as $index=>&$value) {
if ( ($index+1)<  count($array) ) {
$array[$index+1] += $value;
}
echo $value." ";
}
echo "";
foreach ($array as $index=>&$value) {//<- assign $value by reference
echo $array[6]." ";
}
echo "";
echo $array[6];

you finally get the correct result:
0 1 3 6 10 15 21
21 21 21 21 21 21 21
21

You can test this with multiple foreach loops and get the same results. If
you modify the array in the first foreach loop, then use an assign $value by
reference in the next 9 foreach loops to get the correct values (without
modifying the array), and then in the 10th foreach loop you don't use an
assign $value by reference (without modifying the array), the array becomes
corrupted.

I sort of understand the need to assign the $value by reference in the first
loop, but why is it also required in every subsequent loop where the array
is not being modified? Especially since all the examples in the manual show
it's not needed? It would appear that once you've modified an array's
elements in a foreach loop you always have to assign $value by reference in
any subsequent foreach loop using that array. And if you don't, not only
will you get the wrong results but the array itself is actually altered,
even if there's no code in the loop to alter it. Is that correct or is it a
bug? At what stage can you start using the array in the "normal" way again?
That could create hair-pulling havoc for anyone maintaining code if they
haven't noticed that somewhere previously there was code that modified the
array in a foreach loop. Maybe the answer is to always assign $value by
reference in a foreach loop regardless of what you do in that loop, but I'm
not sure what the implications are.


Here's how you should do it (IMHO) to avoid all sorts of side effects, 
magic behaviour, and unnecessary complications:




Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legal

Re: [PHP] set_error_handler() only triggering every Nth time

2012-03-22 Thread Robert Cummings

On 12-03-22 03:57 PM, Daevid Vincent wrote:

Resending since I didn't get a single reply. Maybe it got lost?

-Original Message-
Sent: Tuesday, March 13, 2012 5:58 PM

I am implementing a custom error handler and started noticing some bizarre
behavior. Every Nth time I refresh the page, I see the error/output.


Have you tried sending headers that disable caching?

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 03:54 PM, Jay Blanchard wrote:

[snip]

At one point you indicated all the data was coming from one table. Can you send 
me the table fields and indicate which fields are used to determine parent 
child relationship? Also 2 sample rows of data which have a relationship would 
be helpful.

[/snip]

Columns - tier1, tier2, tier3, tier4 etc. (ends with tier14)

Children of tier1 are tier2 -

select distinct tier2 from table where tier1 = "foo" and company = "1"
select distinct tier2 from table where tier1 = "bar" and company = "1"
etc.

Children of tier2 are tier3, etc.

tier1   tier2   tier3
1,  executive,  ceo,ceo
1,  executive,  vp-ops, vp-ops
1,  executive,  vp-admin,   vp-admin mgr
1,  executive,  vp-admin,   vp-admin ops mgr
1,  executive,  vp-admin,   vp-admin mgr
1,  executive,  vp-admin,   vp-admin clerk
1,  professionalpro-mgr pro-admin
1,  professionalpro-IT  pro-dev
1,  professionalpro-IT  pro-infra
1,  professionalpro-IT  pro-dev
1,  technician  tech-admin  tech-admin mgr
1,  technician  tech-opstech-ops mgr

Thanks for all of your help. I know I am being a PITA.


Your data structure doesn't appear to be very ummm normalized... 
Nonetheless, the following should do it:


query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$id = $row['id'];

unset( $child );

$child = array
(
'id'   => $id,
'parentId' => false,
'children' => array();
);

$root[$id] = &$child;
$children[$id][] = &$child;
}
}

//
// Establish the nested levels.
//

for( $tier = 2; $tier <= 14; $tier++ )
{
if( !($parents = &$children) )
{
break;
}

$parentTier = $tier - 1;

$parentIds = array();
foreach( array_keys( $parents ) as $parentId )
{
$parentIds[$parentId] = $db->quote( $parentId );
}

$query =
"SELECT DISTINCT "
   ."   tier{$tier} AS id, "
   ."   tier{$parentTier} AS parentId "
   ."FROM "
   ."   tiers "
   ."WHERE "
   ."   company = {$company} "
   ."   AND "
   ."   tier{$parentTier} IN (".implode( ',', $parentIds ).") ";

if( $db->query( $query ) )
{
unset( $children );
$children = array();
while( ($row = $db->fetchRow()) )
{
$id  = $row['id'];
$pid = $row['parentId'];

unset( $child );

$child = array
(
'id'   => $id,
'parentId' => $pid,
'children' => array();
);

$children[$id][] = &$child;

foreach( $parents[$pid] as &$items )
{
foreach( $items as &$item )
{
$item['children'][$id] = &$child;
}
}
}
}
}

$json = JSON_encode( $root );
?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 01:06 PM, Jay Blanchard wrote:

On 3/22/2012 11:40 AM, Robert Cummings wrote:

What's the field for which you are selecting data? I've written this
up as a parent/child relationship but it works for data/sub-data
relationships also.

SELECT itemId, otherData FROM table WHERE "some condition";

SELECT itemId, subData FROM otherTable WHERE itemId IN (id1, id2, ...);

Then just link up the sub-data to the primary data in a loop and
finally generate your JSON.

Does that clarify?

[/snip]

I must confess that the raging sinus headache and my general confusion
makes this really unclear for me today. Maybe I should just set it aside
for a day or so. I am super dense today.


Rest might do you well on a number of levels :)


For each level I am selecting for each parent in the level above. Let's
say that level 2 contains 8 people. Level 3 contains 14 people. Only
some of the 14 belong to the 8 and must be associated properly. So how
can I, with one query, associate level 3' 8th, 9th and 10th people with
level 2's 6th person keeping in mind that the 9th person might also
belong to level 2's 4th person.


At one point you indicated all the data was coming from one table. Can 
you send me the table fields and indicate which fields are used to 
determine parent child relationship? Also 2 sample rows of data which 
have a relationship would be helpful.



Just link up the sub-data? Place this array into a child array of the
parent array? Again I apologize - maybe I should push away and let the
customer know that it'll be a couple of more days.


Yeah... child array... 'children' :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 12:34 PM, Jay Blanchard wrote:

[snip]

Sorry, I just realized I didn't make the optimization explicitly
obvious... when I say "Select the children" I mean to select them
using an IN( id1, id2, id3 ) clause instead of a query for each. This
is why we build the array of parent IDs (also I wrote build an array
of "child IDs", it should have read "parent IDs" and has been fixed
above :).

[/snip]

SELECT DISTINCT children FROM table WHERE column1 IN(id1, id2, id3) ?

I am sure I am not following you now. Maybe I didn't explain clearly?


What's the field for which you are selecting data? I've written this up 
as a parent/child relationship but it works for data/sub-data 
relationships also.


SELECT itemId, otherData FROM table WHERE "some condition";

SELECT itemId, subData FROM otherTable WHERE itemId IN (id1, id2, ...);

Then just link up the sub-data to the primary data in a loop and finally 
generate your JSON.


Does that clarify?

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 11:58 AM, Jay Blanchard wrote:

[snip]

Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 1 queries to the
database on every page. Instead, create a layered approach:

 1. Select your root elements.
 2. Loop over in PHP and create an array of parent IDs.
 3. Select the children from the database.
 4. Go to step 2.

This way you will only every perform "depth" number of queries.

[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?


Sorry, I just realized I didn't make the optimization explicitly 
obvious... when I say "Select the children" I mean to select them using 
an IN( id1, id2, id3 ) clause instead of a query for each. This is why 
we build the array of parent IDs (also I wrote build an array of "child 
IDs", it should have read "parent IDs" and has been fixed above :).


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 11:58 AM, Jay Blanchard wrote:

[snip]

Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 1 queries to the
database on every page. Instead, create a layered approach:

 1. Select your root elements.
 2. Loop over in PHP and create an array of child IDs.
 3. Select the children from the database.
 4. Go to step 2.

This way you will only every perform "depth" number of queries.

[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?


It definitely reduces the queries... your current method gets all the 
first level nodes in one query, then performs a query for every single 
parent node. Mine only performs a query for each level in the tree. If 
you have 5 nodes at the first level you will perform 6 queries. Mine 
will perform 2.


To generate the nesting structure at each level you track the level 
members. Something like the following (untested pseudoish):




Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-22 Thread Robert Cummings

On 12-03-22 11:28 AM, Jay Blanchard wrote:

[snip]
...stuff...
[/snip]

Here is the explanation for what I have done and what I am trying to do
- (based on the customer's request).

A week or so ago I took a set of queries from one table and made them
into an unordered list. This will be pseudo-code so that you get idea.

SELECT DISTINCT column1 FROM table
WHERE company = '1'

while($column1 = mysql_fetch_array($query1results)){
  SELECT DISTINCT column2 FROM table
  WHERE company = '1'
  AND column1 = $column1[0]

  while($column2 = mysql_fetch_array($query2results)){
  SELECT DISTINCT column3 FROM table
  WHERE company = '1'
  AND column2 = $column2[0]
  }
}

This continues for up to 14 columns of data. I'm not worried about the
recursive data retrieval, I have that part and like I said - I can
output a nested unordered list from it quite handily.

Now the customer wants JSON as the output. The JSON must reflect the
children properly.

So I have two choices, a multidimensional array that I can use
json_encode() on or output a string that ultimately forms the JSON. We
have all agreed that doing an array would be the best thing but I cannot
wrap my head around it.

If you have more questions fire away - I'd love to get this solved and
off of my plate.


Fix this code... I've come across codebases that did this specific type 
of nested querying and it resulted in 1 queries to the database on 
every page. Instead, create a layered approach:


1. Select your root elements.
2. Loop over in PHP and create an array of child IDs.
3. Select the children from the database.
4. Go to step 2.

This way you will only every perform "depth" number of queries.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Robert Cummings

On 12-03-21 04:42 PM, Jay Blanchard wrote:

[snip]

Why are you trying to create the JSON structure in parts? When I have nesting 
like this i build the full nested structure as PHP, then export to JSON.

[/snip]

As PHP? An array?


Yeah sorry... you know what I meant ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Thinking out loud - a continuation...

2012-03-21 Thread Robert Cummings

On 12-03-21 03:52 PM, Jay Blanchard wrote:

[snip]

I would, yes, but that's not the point.  Is Anna single?  I'm
ready to trade Debs in for a newer model.

[/snip]

I'm thinking that Debs would upset your array if you traded her in.

Anyhow, I have spent the last hour trying to output valid JSON but the whole 
thing is making me barking mad. I may try create a multidimensional array here 
in a little bit. After I go for a walk.


Hi Jay,

Why are you trying to create the JSON structure in parts? When I have 
nesting like this i build the full nested structure as PHP, then export 
to JSON.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] CMS identification

2012-03-18 Thread Robert Cummings

On 12-03-18 06:42 PM, Stuart Dallas wrote:

On 18 Mar 2012, at 22:32, Alain Roger wrote:


ok so here it is: 
http://i220.photobucket.com/albums/dd277/alainroger/cms-login.png


Pass, not one I'm familiar with and a Google Image search for cms login doesn't 
show anything similar. If I were you I'd tell him to give me access to it so I 
can have a look for myself.


On google image search click on the camera icon... then paste in the URL 
with the screen shot.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] iphone & php

2012-03-05 Thread Robert Williams
On 3/5/12 11:58, "Jim Giner"  wrote:


>"Marc Guay"  wrote in message
>news:CAL0DAJq0y-iOMvt4Ko+D4Z_t+oo3PT9SYmR+9foa=9q9gsr...@mail.gmail.com...
>> And if you change your input type to "date", because it's a date, does
> that bring up the numeric keys as well?
>
>actually I have not seen anything that suggests that is a possible
>option.
>I am about to test something that I just received from Apple tho..

Yep, it's in there, as part of HTML 5. In iOS, support for it was added
with Safari 5, so that's probably why the behavior of the 'number' type
changed. There are others, too; see:

<https://developer.apple.com/library/safari/#documentation/appleapplication
s/reference/SafariHTMLRef/Articles/InputTypes.html>
<http://www.w3schools.com/html5/att_input_type.asp>


Regards,
Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



[PHP] time/task reporting

2012-03-01 Thread Robert Nilsson
Hi,
 Ok, I admit -I'm lazy!
 Been asked to make a reporting tool, what and how many hours spent on
 Possible with a save option, to enable continuously adding during the week, 
before sending off by mail to manager and one self.

 Surely I'm not the first person looking at a similar tool, been searching a 
bit but not found example code to use for adjustment to suite my group needs.

 Anyone care to share or point me to a site where I can find this?

 Thanks


Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Robert Cummings

On 12-02-08 01:12 PM, Micky Hulse wrote:

On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummings  wrote:

JavaScript in Internet Crapsplorer spanks you on the bottom every time you
have a trailing comma in a JS array. That may be where you picked up the
aversion.


On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulse  wrote:

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D


Jinx! You owe me a Coke!!! :)


The timestamps above clearly show I was first ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

On 12-02-07 02: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:



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


JavaScript in Internet Crapsplorer spanks you on the bottom every time 
you have a trailing comma in a JS array. That may be where you picked up 
the aversion.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
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-07 Thread Robert Williams
On 2/7/12 13:15, "Paul M Foster"  wrote:


>I've always avoided trailing array commas, but only because I was under
>the impression that leaving one there would append a blank array member
>to the array, where it might be problematic. Yes? No?

Nope. In fact, it's officially supported syntax:

<http://us3.php.net/manual/en/function.array.php>

I love it, particularly when used with the already-noted multi-line array
syntax (I don't recommend it with single-line arrangements):

$foo = array(
   1,
   2,
   3,
); //$foo

This makes it dead easy to add, remove, or reorder elements without
worrying about accidentally breaking the syntax. Much like always using
braces around flow-control blocks, this practice makes future bugs less
likely to be born.

Now if only we could have support for trailing commas in SQL UPDATE/INSERT
field and value lists


Regards,
Bob


--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/





Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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

On 12-02-06 11:35 AM, Alain Williams wrote:

On Mon, Feb 06, 2012 at 09:28:10AM -0700, Larry Martell wrote:

On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams  wrote:



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.


And your point is ?

It just means that someone in the FAA does not like GOTO.
If you can come up with their reasoned argument for the ban I will look at it,
but without that the data point does not have much value - IMHO.


The date for when the ban was imposed might be interesting too... 
perhaps it hasn't been revisited since the 70s.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Long Live GOTO

2012-02-06 Thread Robert Cummings

On 12-02-06 11:58 AM, Tim Streater wrote:

On 06 Feb 2012 at 09:48, Adam Richardson  wrote:


On Mon, Feb 6, 2012 at 4:25 AM, Adam Richardsonwrote:


On Mon, Feb 6, 2012 at 4:07 AM, Tim Streater  wrote:



I disagree that the nested function is a straw-man. I (just as the other
authors I'd linked to describing the "arrow" pattern of code) have seen
plenty of examples of similar code.


I guess what I meant was, that I'd never have written it that way in the first 
place, so as an example it felt contrived. Amateurs or people with no training 
(in particular physicists at CERN 40 years ago) should be kept well clear of 
the goto. I'd probably write your function like this:

function val_nested ($name = null, $value = null, $is_mutable = false)
  {

  static $values   = array();
  static $mutables = array();

  if  ($name===null)  return $values;

  if  ($value===null)  return isset($values[$name]) ? $values[$name] : null;

[-- SNIPP --]

I always add blank lines for clarity. Remove those and the above is 30% shorter 
than yours - as far as I could tell, none of the else clauses was required.

My approach is:

1) deal with the trivial and error cases first


Some say you should never return early from a function... I too think 
that early returns can improve the readability of a function-- 
especially if they are short snippets of logic that clearly indicate the 
reason for an early exit (usually edge case constraints).


:)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Long Live GOTO

2012-02-06 Thread Robert Cummings

On 12-02-06 04:07 AM, Tim Streater wrote:

On 06 Feb 2012 at 07:47, Adam Richardson  wrote:


While not purely focused on PHP, I toss this out to the group because I
believe there are some novel, interesting points regarding the potential
benefits of using the goto construct as implemented in PHP:

http://adamjonrichardson.com/2012/02/06/long-live-the-goto-statement/


Your val_nested() function looks like a straw-man to me. I've not used a goto 
since I stopped writing in FORTRAN in 1978, and not missed it [1]. Neither do I 
ever have deeply nested if-then-else - these are a good source of bugs. I 
suppose the rest of your article might have been dealing with simplifying 
val_nested() but TBH I wasn't interested enough to find out.

[1] Not quite true - a Pascal compiler I once had to use in 1983 lacked a 
return statement, so I had to fake it by putting a 999: label at the end of the 
function and goto-ing to that.


Goto has it's uses, demonizing it due to the poor implementation and 
misuse of it's same-named historical counterparts is an exercise in 
closed-mindedness. Goto can really shine in parsers and various other 
scenarios. While the example shown may be contrived it doesn't miss the 
point. Since goto cannot jump out of the function nor jump into the 
function it is well constrained to provide readability while eliminating 
complexity. Additionally, it is quite likely that it is more optimal. A 
single jump target versus one or more state variables to control nested 
conditionals or loops results in faster execution (also important for 
parsers).


I've had a strong opinion on goto for a very long time. I was one of the 
proponents who argued on internals for its inclusion several years ago. 
I stand by its utility and refer the reader to the fact that many open 
source projects, especially ones that use some kind of parser, have goto 
hidden within their implementation. You can find it in the C code for 
the PHP, MySQL, and Apache to name a few easily recognizable projects.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Robert Cummings

On 12-01-23 09:29 PM, Alex Nikitin wrote:

Have you done image processing? In my experience, with image
generation, photography and processing, typically you are bound by
resources when processing large amount of files than your connection,
or sometimes even disk io.


It really depends on what you're doing with images, if it's intensive 
processing that's already implemented in the gd or imagick library to 
which you can just punt, then how much overhead do you think PHP is 
really going to add since these are C implemented libraries? Sure, if 
you are manipulating pixels one by one within your PHP code you may be 
running into resource issues, but for scaling images, or cropping, or 
even clipping and overlaying... you're not usually doing a whole lot 
within PHP itself. The love is happening in the C code in these cases. 
This is why when working with these libs you get a resource handle and 
not a string. The resource handle almost certainly maps to a native GD 
or imagick structure.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Robert Cummings

On 12-01-23 01:32 PM, Alex Nikitin wrote:

If you don't mind me asking, if you want performance, which is kind of
essential if you are processing a large number of files, why are you
doing it in PHP?

--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late.  ~Seymour Cray


Hi Alex,

If you're processing a large number of files, the bottleneck could just 
as likely be the hard drive read/write and not so much PHP. And what's a 
large number of files? 50? 100? 1000? 100? Remember, PHP internal 
functions are usually wrappers around compiled C code... the shuffling 
around in the PHP engine itself can be quite tiny.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Numeric help needed

2012-01-15 Thread Robert Williams
On Jan 15, 2012, at 19:00, "Simon J Welsh" 
mailto:si...@welsh.co.nz>> wrote:

On 16/01/2012, at 2:48 PM, Chris Payne wrote:

"If the loan amount is $68500.00, the insurace will be based on
$69000.00 as the amount is always rounded up to the next $1000."

The round() function only rounds decimal values. You can use this to emulate 
rounding to a near power of ten by dividing, rounding, then multiplying again. 
i.e. echo "" . round(68500/1000) * 1000 . " ROUNDED";

You can also pass a second parameter to round() that indicates the precision to 
round to. If you pass a negative precision value, you can round to higher-order 
digits. For example, pass -3 to round to the nearest thousand.

Having said that, based on the quote above, I believe this would be an 
incorrect solution to the problem. It sounds like the value is simply always 
rounded up to the nearest thousand, which means round() is not the function to 
use as it will sometimes round down. Instead ceil() should be used, as it 
always rounds up to the next whole number/integer. It lacks a precision 
argument, however, so the OP would need to use the divide-adjust-multiple trick 
you provided to make it work. That is, something like this:

$newValue = ceil(68500 / 1000) * 1000

Numbers smaller than 1000 will need to be handled as an edge case, since this 
algorithm will "adjust" them to zero for you (same as when using round(), 
incidentally). If negative numbers are valid inputs, they'll also need careful 
review to ensure correct behavior.

Hope that helps.

--
Bob Williams


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).


Re: [PHP] PDF Printing instead?

2012-01-06 Thread Robert Williams
On 1/5/12 14:40, "Paul M Foster"  wrote:


>The fpdf and/or tcpdf libraries are the standard answers to this.

Depending on requirements, another good option may be Pdftk. Where TCPDF
is focused on document creation, Pdftk is focused on document
manipulation, and because it's a compiled binary that you install, it's
very fast (and easily used from PHP via exec() and family).


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] New to mac and trying to define a php.ini file.

2012-01-04 Thread Robert Williams
On 1/4/12 14:34, "Tim Streater"  wrote:

>As I hinted in my previous mail, client and server side of my app are
>always on the user's machine. When the user starts the app, I create an
>apache config file on the fly and run an instance of apache just for the
>user. So I'm not messing with the standard OS X Web Sharing. For the same
>reason, I don't want to start modifying or creating a php.ini file.

In that case, you might consider setting it via the Apache config file
that you're creating, which you can do with something like:

php_value date.timezone 'America/Phoenix'

That'll have the same effect (and benefits) as setting it via php.ini.

>>Hmm, just looked more carefully at the docs. I see I'm going to have to
>>add a prefs setting so the user can tell my app what timezone they are
>>in. I find it odd that the OS can't provide this information.

Well, it typically can, or at least can make a guess at it. The problem is
that it's not something you can rely on across different OSes, as some
handle it differently, or less reliably, or not at all. Basically, the
result is non-deterministic. It's for this reason that, as of 5.4, PHP
won't even ask the OS but will always return UTC (and complain a bit) if
something else hasn't been set. This way, you at least have a chance of
consistent results.

If you're only supporting OS X, you can have your script that generates
the Apache config file retrieve the system time zone, and then use that
value in the php_value setting. If the script is in PHP, you can do this:

$timeZone = `/usr/sbin/systemsetup -gettimezone`;


Which just calls the systemsetup command line utility (basically, a CLI
front-end to the settings controlled via System Preferences). Here's what
that call returns when run on the command line on my system:

    H012316WHPV:~ rewilliams$ systemsetup -gettimezone
Time Zone: America/Phoenix



Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] New to mac and trying to define a php.ini file.

2012-01-04 Thread Robert Williams
On 1/4/12 13:33, "Tim Streater"  wrote:


>What I do seem to have is /etc/php.ini.default which I suppose you could
>rename to php.ini if you really wanted to modify it.

Yes, this is correct. I'm not sure if Apple started doing this with Lion
or before, but they give you the .default file to rename (or better, copy)
as php.ini if you desire. Note that the .default file isn't actually used
by PHP, but rather is merely intended to be used as a template.

Also, if I remember right, Apple sets up Apache so that each user has
his/her own config file inside the conf folder. You should make any config
changes, such as turning on PHP, in there, rather than in the primary
config file. The latter is subject to being overwritten on OS updates and
upgrades, while the former is not. Segregating your changes also makes it
easier to tell exactly what you've changed from the defaults.

>I'm however carefully ensuring that the client and server aspects of my
>app (which will both run on the user's machine) don't use anything except
>what comes with the standard OS X distribution, so to fix the date time
>issue I do:
>
>  date_default_timezone_set (@date_default_timezone_get ());

I recommend against this. First of all, in PHP 5.4, this is just going to
return UTC if you haven't explicitly set the time zone, and that's
probably not what you want. Plus, the use of @ here leaves a nasty taste
in the mouth (as it does in most cases).

Instead, I suggest creating a php.ini file and changing this setting there
by setting it to a specific time zone. For example, in mine, I have this
line:

date.timezone = 'America/Phoenix'

This ensures that PHP is always using the same zone no matter what script
is running, avoids PHP errors if you forget to make the change in a
script, avoids you having to modify all your scripts in the first place,
and lets you easily change the time zone used by your applications to
whatever you want independently of the server's own time zone (or in 5.4,
to something other than UTC).


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] number_format

2011-12-19 Thread Robert Cummings

On 11-12-19 11:08 AM, Bastien Koert wrote:

On Mon, Dec 19, 2011 at 9:19 AM, Floyd Resler  wrote:

In the previous version of PHP we were using, I could pass a string to number_format and 
it would just change it to a 0 without complaint.  With 5.3.6 I get an "expects 
double" error.  I don't suppose there's a way to make it work like it used to???  
I'm dealing with really old code that wasn't very well structured.

Thanks!
Floyd


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




Could you check it before formatting? Or if the data is coming from
the db, force it to 0 if null?

$var = (is_double($number_var)) ? $number_var : 0;


Or possibly:



Cheers,
Rob.







--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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