php-general Digest 12 Oct 2009 05:36:15 -0000 Issue 6386
Topics (messages 298836 through 298848):
Re: Insult my code!
298836 by: Eric Bauman
Re: How do YOU set default function/method params?
298837 by: Jim Lucas
php exception handling
298838 by: Lars Nielsen
298840 by: Tommy Pham
298841 by: Larry Garfield
298842 by: Al
Re: Newbie: Array of objects iteration
298839 by: Tommy Pham
Need unrounded precision
298843 by: Andre Dubuc
298844 by: Eddie Drapkin
298846 by: Jim Lucas
298847 by: Andre Dubuc
Re: Need unrounded precision [RESOLVED]
298845 by: Andre Dubuc
security/deployment issue
298848 by: Augusto Flavio
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On 7/10/2009 5:34 PM, Eric Bauman wrote:
Hi there,
I'm in the process of trying to wrap my head around MVC, and as part of
that, I'm attempting to implement a super-tiny MVC framework.
I've created some mockups of how the framework might be used based
around a very simple 'bank', but I'm trying to get some feedback before
I go and implement it, to make sure I'm actually on the right track.
Any thoughts would be much appreciated!
Model - http://www.pastebin.cz/23595
Controller - http://www.pastebin.cz/23597
View - http://www.pastebin.cz/23598
Template - http://www.pastebin.cz/23599
Hi again,
I've done quite a bit of reading, thinking and coding based on all the
feedback I received from my original post.
I have since come up with this:
Model - http://www.pastebin.cz/23857
Controller - http://www.pastebin.cz/23858
View - http://www.pastebin.cz/23859
Persistence - http://www.pastebin.cz/23860
As before, please feel free to insult my code. ;-) Any and all feedback
is of course most appreciated.
Best regards,
Eric
--- End Message ---
--- Begin Message ---
Stephan Ebelt wrote:
> On Mon, Oct 05, 2009 at 05:48:32PM -0700, Jim Lucas wrote:
>> Here is a problem that I have had for years now. I have been trying to come
>> up
>> with the perfect solution for this problem. But, I have come down to two
>> different methods for solving it.
>>
>> Here is the problem...
>
> [...]
>
>> Now, we all have a function or method like this floating around somewhere.
>>
>> My question is, how do YOU go about setting the required entries of the
>> $headers
>> array() ?
>>
>
> [...]
>
>> END of examples...
>>
>> Now, IMO, the last one is the simplest one and for me, I think it will be the
>> new way that I solve this type of problem.
>>
>> But, my question that I put out to all of you is...
>>
>> How would you solve this problem?
>
> I have use this array_merge() approach mentioned in other posts for
> quite some time but found that it introduced many bugs when fieldnames
> changed.
> Ie. if the defaults come from a database table and I changed the schema it
> caused undefined values during the merging and - worse - sometimes messed up
> the
> inner workings of functions...
>
> Then I heard of the "value object" approach somewhere and found that much more
> solid. One would basically define a class where default values are represented
> by its properties. Ie:
>
> class vo_email extends vo {
> public $to = '';
> public $from = '';
> public $subject = '(no subject)';
> public $body = '';
> ...
> }
>
> the constructor can make sure that absolutly necessary values are required and
> set properly - and could complain if something is not right. There could be
> methods that add() or set() or change() things. These could also be inherited
> from a very generic class "vo" so that this stuff is written once and applies
> to all sorts of defaults in the program.
> In my app the inherited constructor accepts arrays as parameter and assigns
> their elements to the object properties and - by that - overwrites the default
> settings. If elements do not match with the defined properties it will trigger
> a very visible call trace.
>
> A function like sendEmail() would then require a object of type vo_email as
> parameter and would work with its properties internally and can rely on it as
> the vo's constructor should have catched anything bad.
>
> If additional logic for the input values is required, it can be added easily:
>
> class dao_email extends vo_email {
> ...
> public function encode_body() {
> ...
> }
>
> public function sanitize_mail_address() {
>
> }
> ...
> }
>
This is a very interesting approach. How would you initialize the class? Using
a Singleton Method, or a Globally available class variable?
> sendEmail() would then require a dao_email object (dao=data access object) as
> input.
>
> stephan
>
>> TIA
>>
>> Jim Lucas
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Hi,
I am trying to make an exception class that emails the errors to myself.
I have started by using the example by ask at nilpo dot com on
http://dk2.php.net/manual/en/language.exceptions.php.
It work ok but i want it NOT to show the errors on the php-page but only
show the details in the email and then just write eg "An error occurred"
or so on the webpage. Can anyone give me a hint about how to achieve
this?
Regards
Lars Nielsen
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Lars Nielsen <[email protected]>
> To: [email protected]
> Sent: Sun, October 11, 2009 2:18:03 PM
> Subject: [PHP] php exception handling
>
> Hi,
>
> I am trying to make an exception class that emails the errors to myself.
> I have started by using the example by ask at nilpo dot com on
> http://dk2.php.net/manual/en/language.exceptions.php.
>
> It work ok but i want it NOT to show the errors on the php-page but only
> show the details in the email and then just write eg "An error occurred"
> or so on the webpage. Can anyone give me a hint about how to achieve
> this?
>
> Regards
> Lars Nielsen
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Lars,
Here's a pseudo code:
try {
if (!$valid) {
throw new Exception("Test failed.");
} else {
// do something
}
} catch (Exception $e) {
// set/print a user friendly message to send to output
// set a detailed message using debug_backtrace() or any other information
relevant for easier troubleshooting
// log and/or email detailed message
}
Regards,
Tommy
--- End Message ---
--- Begin Message ---
On Sunday 11 October 2009 6:09:46 pm Tommy Pham wrote:
> Lars,
>
> Here's a pseudo code:
>
> try {
> if (!$valid) {
> throw new Exception("Test failed.");
> } else {
> // do something
> }
> } catch (Exception $e) {
> // set/print a user friendly message to send to output
>
> // set a detailed message using debug_backtrace() or any other
> information relevant for easier troubleshooting // log and/or email
> detailed message
> }
>
> Regards,
> Tommy
Actually the else clause is not necessary. That's one of the nice things
about exceptions. If you throw an exception, processing jumps to the
appropriate catch and never returns.
try {
// Do normal stuff.
if (!$valid) {
throw new Exception('OMG!');
}
// Do more normal stuff.
}
catch (Exception $e) {
// Print user friendly message.
// Log detailed information or whatever you're going to do.
}
--
Larry Garfield
[email protected]
--- End Message ---
--- Begin Message ---
Lars Nielsen wrote:
Hi,
I am trying to make an exception class that emails the errors to myself.
I have started by using the example by ask at nilpo dot com on
http://dk2.php.net/manual/en/language.exceptions.php.
It work ok but i want it NOT to show the errors on the php-page but only
show the details in the email and then just write eg "An error occurred"
or so on the webpage. Can anyone give me a hint about how to achieve
this?
Regards
Lars Nielsen
Don't sell exception handling short; it can be very useful for processing
control. Here is an example of a sequence of user input validations and checks.
All check functions throw an exception, with the details, if they find an error.
e.g., "Tag <spen> is invalid. Check spelling". This message is rendered so the
user can correct his/her mistake.
if(!empty($adminMiscSettingsArray['instrText']))
{
try{
checkValidTags($validHTMLtags,
allProxyTagsArray,adminMiscSettingsArray['instrText']);
checkTagMatching($emptyProxyTagsArray,$adminMiscSettingsArray['instrText']);
checkTagNesting($emptyProxyTagsArray, $adminMiscSettingsArray['instrText']);
checkTextLinks($linksProxyTagsArray, $adminMiscSettingsArray['instrText']);
}
catch (Exception $e){
$instrCheckErrorMsg = $e->getMessage();
}
--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: MEM <[email protected]>
> To: Tommy Pham <[email protected]>; [email protected]
> Sent: Sat, October 10, 2009 2:49:23 AM
> Subject: RE: [PHP] Newbie: Array of objects iteration
>
> >
> > MEM,
> >
> > http://www.php.net/language.oop5.reflection
> >
> >
> > Regards,
> > Tommy
> >
> >
>
>
> And brand new world opens in from of my eyes... O.O.
>
> I will search more info on this on the net... just for the records, as
> properties names is concern, I couldn't find any better I suppose:
> http://pt.php.net/manual/en/reflectionproperty.getname.php
>
>
> I'm just wondering, we call it like this?
> $property = new ReflectionProperty($myproperty);
> $proptertyName = $property->getName();
>
>
> Can we called statically like this?
> $propertyName = ReflectionProperty::getName($myproperty); -> this would
> be nice. :)
>
> The documentation is a little bit lacking, and I'm a little bit newbie, is
> this correct?
>
> Note:
> The array_keys as a possibility to retrieve ALL keys from a given array. It
> would be nice to retrieve ALL properties names at once as well...
> :)
>
>
>
> Regards,
> Márcio
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Márcio,
Sorry, I don't remember since it's been over 5 years I used reflection.
Reflection has many uses, 1 of it is that it allow you reverse engineer any PHP
app ;)
Regards,
Tommy
--- End Message ---
--- Begin Message ---
Hi,
I need to extract the first digit after the decimal point from a number such
as 28.56018, which should be '5'.
I've tried a few methods to accomplish this. If I use 'ini_set' I would need
to know the number of digits before the decimal (which, unfortunately, I
would not have access to).
Then I've tried:
<?php
$elapsed = 28.56018;
$digit = round($elapsed, 1); // rounds result is '6'
$digit = number_format($elapsed, 1); // still rounds result to '6'
?>
What I need is only the first digit after the decimal -- all the rest could
be 'chopped' or discarded but without rounding the first digit after the
decimal point.
Is there any way of doing this?
I'm stumped.
Tia,
Andre
--- End Message ---
--- Begin Message ---
On Fri, Jan 1, 2010 at 9:20 PM, Andre Dubuc <[email protected]> wrote:
> Hi,
>
> I need to extract the first digit after the decimal point from a number such
> as 28.56018, which should be '5'.
>
> I've tried a few methods to accomplish this. If I use 'ini_set' I would need
> to know the number of digits before the decimal (which, unfortunately, I
> would not have access to).
>
> Then I've tried:
>
> <?php
>
> $elapsed = 28.56018;
>
> $digit = round($elapsed, 1); // rounds result is '6'
> $digit = number_format($elapsed, 1); // still rounds result to '6'
>
> ?>
>
> What I need is only the first digit after the decimal -- all the rest could
> be 'chopped' or discarded but without rounding the first digit after the
> decimal point.
>
> Is there any way of doing this?
>
> I'm stumped.
>
> Tia,
> Andre
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Try sprintf with a format of %0.1f.
--- End Message ---
--- Begin Message ---
Andre Dubuc wrote:
Hi,
I need to extract the first digit after the decimal point from a number such
as 28.56018, which should be '5'.
I've tried a few methods to accomplish this. If I use 'ini_set' I would need
to know the number of digits before the decimal (which, unfortunately, I
would not have access to).
Then I've tried:
<?php
$elapsed = 28.56018;
$digit = round($elapsed, 1); // rounds result is '6'
$digit = number_format($elapsed, 1); // still rounds result to '6'
?>
What I need is only the first digit after the decimal -- all the rest could
be 'chopped' or discarded but without rounding the first digit after the
decimal point.
Is there any way of doing this?
I'm stumped.
Tia,
Andre
FYI: did you know that your computer thinks it is in the future?
You need to check your date settings...
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
Yup! I had noticed that I had forgot to reset to today's date after working on
the code, just after I sent the messages.
Thanks.
Andre
On October 11, 2009 09:14:56 pm Jim Lucas wrote:
> Andre Dubuc wrote:
> > Hi,
> >
> > I need to extract the first digit after the decimal point from a number
> > such as 28.56018, which should be '5'.
> >
> > I've tried a few methods to accomplish this. If I use 'ini_set' I would
> > need to know the number of digits before the decimal (which,
> > unfortunately, I would not have access to).
> >
> > Then I've tried:
> >
> > <?php
> >
> > $elapsed = 28.56018;
> >
> > $digit = round($elapsed, 1); // rounds result is '6'
> > $digit = number_format($elapsed, 1); // still rounds result to '6'
> >
> > ?>
> >
> > What I need is only the first digit after the decimal -- all the rest
> > could be 'chopped' or discarded but without rounding the first digit
> > after the decimal point.
> >
> > Is there any way of doing this?
> >
> > I'm stumped.
> >
> > Tia,
> > Andre
>
> FYI: did you know that your computer thinks it is in the future?
>
> You need to check your date settings...
>
> --
> Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
--- End Message ---
--- Begin Message ---
Thanks Eddie,
Actually while waiting for some re[lies, I resolved the problem.
I realized that '$elapsed' will always have only two digits before the decimal
point. Thus I was able to use 'number_format($elapsed, 2);' and to give me
the desired result.
Thanks for the quick reply!
Andre
On October 11, 2009 08:50:11 pm Eddie Drapkin wrote:
> On Fri, Jan 1, 2010 at 9:20 PM, Andre Dubuc <[email protected]> wrote:
> > Hi,
> >
> > I need to extract the first digit after the decimal point from a number
> > such as 28.56018, which should be '5'.
> >
> > I've tried a few methods to accomplish this. If I use 'ini_set' I would
> > need to know the number of digits before the decimal (which,
> > unfortunately, I would not have access to).
> >
> > Then I've tried:
> >
> > <?php
> >
> > $elapsed = 28.56018;
> >
> > $digit = round($elapsed, 1); // rounds result is '6'
> > $digit = number_format($elapsed, 1); // still rounds result to '6'
> >
> > ?>
> >
> > What I need is only the first digit after the decimal -- all the rest
> > could be 'chopped' or discarded but without rounding the first digit
> > after the decimal point.
> >
> > Is there any way of doing this?
> >
> > I'm stumped.
> >
> > Tia,
> > Andre
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Try sprintf with a format of %0.1f.
--- End Message ---
--- Begin Message ---
Hi everybody,
i have a doubt about my security and deployment methods. Today i manage
several projects and these projects are versioned with subversion. My
environment is something like this:
1. The developer make some update in the source code of a project. (from
your IDE, generally netbeans)
2. The developer commit the modifications to the subversion server after
test it(sure).
3. The project manager sync the files from the dev server to the prod
server(using rsync).
Well, my questions are 2. All about the rsync:
1. For each project we have a ssh user that is used to sync the files(source
code) to the prod server. The problem that i see here is that for each
project i need to have a ssh account to sync these files. This is not so
cool because i need to have severals actived ssh accounts in my prod server.
I'm thinking about the root account to do this work. Is this a good
practice?
2. Does have some another way, more better than the rsync for this
deployment issue?
Thanks.
Augusto Morais
--- End Message ---