Re: [PHP] error_handler : unique caller ID ?

2012-11-13 Thread Robert Williams
On 11/13/12 11:20, B. Aerts ba_ae...@yahoo.com 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] Re: PHP as Application Server

2012-09-26 Thread Robert Williams
On 9/26/12 10:18, Matijn Woudt tijn...@gmail.com 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] 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] Awkward time processing

2012-08-02 Thread Robert Williams
On 8/2/12 05:51, Paul Halliday paul.halli...@gmail.com 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 adam.nicho...@hl.co.uk 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 13:21, Simon Dániel simondan...@gmail.com 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] Entry point of an MVC framework

2012-07-12 Thread Robert Williams
On 7/12/12 14:44, Daevid Vincent dae...@daevid.com 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] How does this code work?

2012-07-03 Thread Robert Williams
On Jul 2, 2012, at 22:15, Jim Lucas li...@cmsws.com 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():

?php

function xml_character_encode($string, $trans='') {
$trans = (is_array($trans)) ? $trans : 
get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($trans as $k=$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('Chteau');

Yields this:

Ch#195;#162;teau
Ch#38;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-07-01 Thread Robert Williams
Zend Server includes a job queue.

http://www.zend.com/en/products/server/zend-server-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] help with preg_match

2012-06-03 Thread Robert Williams
On Jun 3, 2012, at 17:28, Chris Purves ch...@northfolk.ca 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] iphone php

2012-03-05 Thread Robert Williams
On 3/5/12 11:58, Jim Giner jim.gi...@albanyhandball.com wrote:


Marc Guay marc.g...@gmail.com 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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Robert Williams
On 2/7/12 13:15, Paul M Foster pa...@quillandmouse.com 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] Numeric help needed

2012-01-15 Thread Robert Williams
On Jan 15, 2012, at 19:00, Simon J Welsh 
si...@welsh.co.nzmailto: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 br . 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 pa...@quillandmouse.com 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 13:33, Tim Streater t...@clothears.org.uk 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] 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 t...@clothears.org.uk 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] Is there a decent design app ?

2011-11-26 Thread Robert Williams
On Nov 25, 2011, at 16:18, Andreas maps...@gmx.net wrote:

 Like you have /foo.css and for some reason or another you move it to
 /lib/css and rename it to bar.css.
 Now it'd be nice if an IDE was aware of all the references within a site
 and update the affected urls.

Check out PhpStorm from JetBrains. I know it handles rename-refactors of PHP 
files, functions, and classes, and I'm nearly positive it does the same 
HTML/CSS/JS files, as well. Ad it's a darn good IDE, to boot.

--
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] What is wrong with this preg_match?

2011-10-27 Thread Robert Williams
On 10/27/11 11:43, Paul Halliday paul.halli...@gmail.com wrote:


if ($argc == 1 || $argc  2 || !preg_match((\d{4}-\d{2}-\d{2}),

Usage: ./process_patches.php -mm-dd

patches@innm2 ~/Code/Oculi $ ./process_patches.php 2011-01-011

The problem is that your expression basically defines a 'contains'-type
search, so it's matching the first 10 characters as required but then
simply ignoring that last, 11th character because there's no requirement
regarding it in the expression.

Try this instead:

^(\d{4}-\d{2}-\d{2})$

The ^ anchors the matching string to the beginning of the string, while
the $ anchors it to the end, which effectively forces the expression to
match the entire string, disallowing extra characters before or after it.


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] FW: parse error

2011-10-13 Thread Robert Williams
On 10/13/11 10:06, David Savage dsav...@cytelcom.com wrote:


php -l voip_cdrs.php
PHP Parse error:  parse error, unexpected T_STRING in
/usr/local/cytrex/voip_cdrs.php on line 1050
Errors parsing voip_cdrs.php

 $alias_sql_stmt=SELECT ani FROM ldrates WHERE
ani='$termnum10';// -this is line 1050

Could you please tell me what's wrong with the line 1050 ?   I've been
pulling my hair out (figuratively speaking) trying to understand why the
compiler sees this line as a problem.  Thanks for whatever help you can
give.

My suspicion is that there's is an unmatched curly brace earlier in the
file. With this type of error, you'll generally get a report of a bad line
further down the file--sometimes way down--because the parser can't
recognize until it hits the later point that something is wrong. Try
double-checking that the {Š} blocks prior to line 1050 properly balance,
and you'll probably find there's an extra one, or that one is missing, etc.

If nothing else, just start stripping code from the file until you find
the line that's actually at fault. If you do this in a binary search
fashion, it won't take more than a few minutes.


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] Variable variable using constant

2011-10-12 Thread Robert Williams
On 10/12/11 11:51, Marc Guay marc.g...@gmail.com wrote:


Let's say that I have 2 constants

DEFINE('DESKTOP_URL_en', http://www.website.com/index.php?page=home;);
DEFINE('DESKTOP_URL_fr',
http://www.website.com/index.php?page=accueil;);

and I would like to populate the value of an href with them depending
on the user's language.  $_SESSION['lang'] is either 'en' or 'fr'.
How would I go about referring to this variable?


Try:

   $var = constant('DESKTOP_URL_' . $_SESSION['lang']);


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] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
As an alternative to the regular expression approaches already provided by
others, you could also use ctype_alnum():

if (ctyp_alnum($_POST['username'])) {
   //username contains only letters and numbers
} else {
   //username contains characters other than letters and numbers
} //if-else

Docs: http://us3.php.net/manual/en/function.ctype-alnum.php


As a bonus, this will likely be quite a bit quicker than the regex-based
approaches. That said, you'd have to be making many calls (e.g., inside a
loop) for the difference to reach the point of being noticeable. For
something like a one-time validation on page-load, use whichever you find
most comfortable.

In your original question, you also mentioned looping through a variable
to check for non-alphanumeric characters. The regex approach or the
approach I outlined above is much better in this case, but as a learning
exercise, you could do the looping like this:

$validCharacters = array('a', 'e', 'i', 'o', 'u');
for ($i = 0; $i  count($_POST['username']); $i++) {
   if (in_array($_POST['username'][$i], $validCharacters)) {
  echo 'Pass!';
  } else {
  echo 'Fail!';
   } //if-else
} //for i

The key thing to note there is that you can treat the string like it's an
array to loop through it. For more information about this, go here:

http://us2.php.net/manual/en/language.types.string.php

and search the page for the phrase String access and modification by
character.







Regards,

--
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 can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
[Redirecting thread back to the list for the benefit of others.]

On 9/22/11 13:38, Eric eric_justin_al...@cfl.rr.com wrote:


So is $_POST[username][0] appropriate or does that only work
with normal variables?

As far as this sort of manipulation goes, $_POST is just like any other
variable. Referencing the 0th element of any string will give you the
first character, if there is one. (If there isn't one, you'll generate a
PHP warning or notice for trying to read out-of-bounds.)

and would this be valid,
$i = 0;
while($_POST[username][$i] != \0)

It looks like you're trying to treat the string as a C-style string. That
won't work in PHP because PHP's strings are not null-terminated. Thus,
this will lead to an infinite loop with any strings that don't happen to
have the null character somewhere within (and most strings won't).

{
if($_POST[username][$i] == . ||  $_POST[username][$i] == ..)

This line is not wrong per-se, but nor does it entirely make sense. When
you access a string as an array, each element contains one character.
Here, you're checking whether each character in turn is a period (fine) or
two periods (makes no sense, since one character cannot represent two
period characters). What you'd probably want to do is simply remove the
second condition, since a check for one period will work just as well if
the name contains two periods. That is:

   if($_POST[username][$i] == .)

Incidentally, another tip: when comparing against a constant, as you are
in both your while() and your if(), place the constant on the left side if
the expression rather than the right. That is, write the previous if()
like this:

   if ('.' == $_POST['username'])

It might look a little funny, but I assure you, someday, it'll save you a
bunch of frustrating debugging time. The reason is that if you mistype the
'==' as '=', you'll do an assignment, the value of which is then returned.
This has the net effect of 1) quietly changing your variable's value, and
2) making the overall expression always evaluate to true, sending you into
the the true part of the conditional branch, well, unconditionally.



--
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] Help on number matching function

2011-09-16 Thread Robert Williams
On Sep 16, 2011, at 6:02, Dare Williams darrenwi...@yahoo.com wrote:


  I have a 5 Digits set of number  and need to match it with another set of 
 five  digits and return how many number are match and the figures that are 
 match.


Check out array_intersect().

http://us.php.net/manual/en/function.array-intersect.php

--
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] lost return value during a static call

2011-09-15 Thread Robert Williams

On Sep 15, 2011, at 6:03, chamila gayan cgcham...@gmail.com wrote:

 when it goes through 2 static methods, at some point it stops returning
 value to the calling method. (please see comments in-line).

The getArray() method and the 'else' portion of the getChild() method both lack 
a return statement, so they're basically just tossing out whatever value they 
come up with.

--
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] Mysqli error handling

2011-08-31 Thread Robert Williams
Okay, so I've finally got an opportunity to start converting our code to
use Mysqli instead of the old mysql_* functions. Mysqli is new to me, but
I thought things were going well until the first time I tried to run a
query with a syntax error in it, and it threw up a PHP warning. Being that
Mysqli is an OO API, I guess I assumed that any errors would simply
surface as exceptions, and indeed, I got an exception in this case. But I
also got a PHP warning containing the same information.

This is the first thing that strikes me as terribly wrong. I think any
API, OO or not, should never spit out errors/warnings/notices for routine
errors (like, in this case, an SQL syntax error). Rather, the
function/method should signal an error through a defined mechanism, such
as the return value (e.g., false on failure), or via an exception for
class methods. This philosophy jives well with my understand of the
direction of error handling in PHP, which is to use exceptions, rather
than errors/warnings/notices, for all the newer OOP APIs.

Secondly, I can't find a good way to handle these warnings. We do all
development with error handling set to E_STRICT | E_ALL, and our general
policy is that no such errors should be generated. This behavior by Mysqli
means that we effectively need to catch SQL problems in both our error
handlers and in our exception handling. I recognize that we could just use
suppression, but that's, well, nasty.

Digging a bit more, I found mysqli_report(). This looks pretty good, but I
find it odd that 1) it's a procedural-only function that controls an OO
API, and 2), it takes affect for the entire request, which effectively
means it has to be set up right for each database access rather than just
once per database instance. I suspect this relates to the underlying
implementation, but it's still quite the letdown.

Is there something I'm missing in all this, or is really as clunky as it
seems? What have those of you with more Mysqli experience found to work
well as a good error-handling pattern when working with it?


--
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] Constants in strings

2011-07-06 Thread Robert Williams
On 2011-07-6 08:09, ad...@buskirkgraphics.com
ad...@buskirkgraphics.com wrote:



I use constants in my OOP and I never use the heredoc syntax. Now I am
fearing that I have not taken advantage of something.
My understanding of heredoc syntax as of 5.3 is just a string quoting
right?
Is there an advantage of using the heredoc syntax over single quoted or
double quoted?

I don't believe that a heredoc will perform significantly differently than
a double-quoted string, as, from the parser's POV, they're essentially the
same thing once you get past the step of extracting the entire string from
the source. I've not verified this by reviewing the relevant source,
however, nor have I benchmarked it. But, I'm willing to bit that even if
there is a difference, it's so small that you're better off worrying about
which will lead to easier code maintenance than worrying about performance
(as is typically the case with such micro-optimization choices).

In my view, what's important is how you use them. In particular, a heredoc
can present a bit more cleanly when you're dealing with a large-ish chunk
of text, as in, say, an e-mail message template. The main downside is that
they will usually make a mess of code formatting, since the closing
delimiter must be against the left margin. For this reason, I tend to
prefer multi-line double-quoted strings over heredocs when I have
meaningful indentation, as in a function or class method. Where I've made
most use of heredocs is when I want to do nothing but define a bunch of
long strings in one file. For example, I might create a file to define a
set of related e-mail message templates:

?php

$accountCreationSuccessfulMessage = EndSuccess
Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget,
tempor sit amet, ante.

Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae
est.

Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper
pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit
amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum
rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis
pulvinar facilisis. Ut felis.
EndSuccess



$accountCreationFailedMessage = EndFailure
Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet
sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus.
Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non
lacus vitae ipsum viverra pretium. Phasellus massa.

Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce
consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim
adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum
nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius
nibh ut lacus. Curabitur fringilla.

Nunc est ipsum, pretium quis, dapibus sed, varius non, lectus. Proin a
quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus volutpat
urna, ut fermentum neque mi egestas dolor.
EndFailure



?

Of course, this is arguably as clean:

?php

$accountCreationSuccessfulMessage = 
Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget,
tempor sit amet, ante.

Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae
est.

Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper
pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit
amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum
rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis
pulvinar facilisis. Ut felis.
; //$accountCreationSuccessfulMessage

$accountCreationFailedMessage = 
Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet
sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus.
Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non
lacus vitae ipsum viverra pretium. Phasellus massa.

Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce
consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim
adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum
nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius
nibh ut lacus. Curabitur fringilla.

Nunc est ipsum, pretium quis, dapibus sed, varius non, lectus. Proin a
quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus volutpat
urna, ut fermentum neque mi egestas dolor.
; //$accountCreationFailedMessage

?

With the latter, there is the catch that you end up with leading and
trailing line breaks, but those are easy enough to deal with, if desired.

As to the original topic of this thread, it's long annoyed me that there's
no easy way to use constants with interpolation. Since I find repeated
concatenation extremely ugly and prone to 

Re: [PHP] PHP to Java integration using : shell_exec function

2011-05-26 Thread Robert Williams
On 2011-05-26 12:00, Eli Orr (Office) eli@logodial.com wrote:

   $EncXML = shell_exec(/usr/bin/java/java -jar MyApp.jar -XML
$XML_toEnc); == ??? How can I pass parameters like a large string of
let say XML?

You're missing the shell escaping. Try something like this:

$xml = 'greetinghello/greeting';
$xml_shell = escapeshellarg($xml);

$result = shell_exec(/usr/bin/java/java -jar MyApp.jar -XML $xml_shell);

See: http://us.php.net/manual/en/function.escapeshellarg.php

If you need to pass the value through standard input, you can pipe it out
of echo:

$result = shell_exec(/bin/echo -n $xml_shell | /usr/bin/java/java -jar
MyApp.jar -XML);

Regards,
Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
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