php-general Digest 5 Sep 2013 10:48:00 -0000 Issue 8357

Topics (messages 322039 through 322046):

Re: Static utility class?
        322039 by: Stephen
        322040 by: Micky Hulse
        322043 by: Rodrigo Santos
        322044 by: Micky Hulse
        322045 by: Robert Cummings

Re: message to user after complete POST
        322041 by: Rodrigo Santos
        322042 by: iccsi

Re: PHP-5.5.2 +opcache segfaults with Piwik
        322046 by: Grant

Administrivia:

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

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

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


----------------------------------------------------------------------
--- Begin Message ---
On 13-09-04 05:09 PM, Micky Hulse wrote:
Thank you so much for the quick and very informative/educational
replies Stephen and David, I really appreciate it! :)

On Wed, Sep 4, 2013 at 12:36 PM, Stephen <stephe...@rogers.com> wrote:
This sounds simply like a library of functions that are implemented using
objects.
Instantiate your static variables in the library file. Again, so that only
happens once.
"functions implemented using objects" sounds like exactly what I want.
Just out of curiosity, and sorry in advance for my ignorance, but does
the code I posted fit that type of pattern? If not, what would I need
to modify and how would I call it?

Actually, I should probably spend some time Googling before I ask you
for more details. :D
Well, your code does not take advantage of the features of classes, but the syntax is correct.

Global, static variables are not consistent with the design concepts of OOP. But as a first step in moving from procedural code to OOP, which is learning the syntax, go for it.

--
Stephen


--- End Message ---
--- Begin Message ---
Thanks Stephen! I really appreciate the help! :)

In my PHP ventures over the years, I haven't made much use of static
variables/methods/properties ... I was thinking they might be useful
for this one bit of code, but based on your feedback (and David's) I
think I'll be heading down a different path.

Thanks again for the kick in the right direction!

Much appreciated!

Cheers,
Micky

--- End Message ---
--- Begin Message ---
Hi, first, sorry for the bad English.

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.

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.


2013/9/4 Micky Hulse <mickyhulse.li...@gmail.com>

> Hi all!
>
> Example code:
>
> <https://gist.github.com/mhulse/6441525>
>
> Goal:
>
> I want to have a "utility" class that contain utility methods which should
> have the option of being called multiple times on a page.
>
> I think my main goal is to avoid having to "new" things ... I don't really
> need to create an instance here (there's no need for a constructor in this
> case).
>
> Question:
>
> Is the above simple pattern a good way to have a class that calls static
> methods?
>
> To put it another way, is there any reason why I would not want to use the
> above code?
>
> Basically I want to wrap these simple functions in a nice class wrapper and
> have the ability to call them without having to jump through more hoops
> than is necessary.
>
> Are there any pitfalls to writing a class like this? Or, is this the
> standard way of writing a simple "utility" class for this type of
> situation?
>
> Please let me know if I need to clarify my questions.
>
> Thanks for your time?
>

--- End Message ---
--- Begin Message ---
Hi Rodrigo, thanks for the help, I really appreciate it!

On Wed, Sep 4, 2013 at 5:55 PM, Rodrigo Santos
<rodrigos.santo...@gmail.com> 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. :)

Have a great afternoon!

Cheers,
Micky

--- End Message ---
--- Begin Message ---
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
<rodrigos.santo...@gmail.com> 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.

--- End Message ---
--- Begin Message ---
hey, if you are just trying to give the user a feedback about the
information sent, there is a Global variable for this, and it's the $_POST.
When you receive the information on the script you called on the "Action"
atribute of the form, via the $_POST global variable, you will test the
information end echo the feedback on that script.

Note that, unless you are using ajax (jquery, or any other javascript ajax
method), when you post a form, you will be intantly redirected to the
"action" path. then you have nothing to do in the source page.

hope you got it.


2013/9/4 iccsi <inu...@gmail.com>

> I have a POST form and action itself like following
> <form name="MyForm"  id="MyForm" method="POST" action="index.php">
> </form>
>
> I want to show success message when POST complete or error message if
> there is any.
> I would like to know are there any property or global variable I can check
> to show message to users.
> If not, it seems that the only solution is jQuery, since it has success
> function that jQuery call after POST.
>
> Your help and information is great appreciated,
>
>
> Regards,
>
> Iccsi,
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Thanks a million for the information and help,
yes, I will use jQuery to have my success function call in jQuery.ajax.

Thanks again,

Regards,

Iccsi,

"Rodrigo Santos" wrote in message news:caombckqonakxoc4tnhcpn2ycdpy8503xttc7sosjywhtd5x...@mail.gmail.com...

hey, if you are just trying to give the user a feedback about the
information sent, there is a Global variable for this, and it's the $_POST.
When you receive the information on the script you called on the "Action"
atribute of the form, via the $_POST global variable, you will test the
information end echo the feedback on that script.

Note that, unless you are using ajax (jquery, or any other javascript ajax
method), when you post a form, you will be intantly redirected to the
"action" path. then you have nothing to do in the source page.

hope you got it.


2013/9/4 iccsi <inu...@gmail.com>

I have a POST form and action itself like following
<form name="MyForm"  id="MyForm" method="POST" action="index.php">
</form>

I want to show success message when POST complete or error message if
there is any.
I would like to know are there any property or global variable I can check
to show message to users.
If not, it seems that the only solution is jQuery, since it has success
function that jQuery call after POST.

Your help and information is great appreciated,


Regards,

Iccsi,


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




--- End Message ---
--- Begin Message ---
>> I've tried php-5.5.2 and 5.5.3 but both segfault with piwik unless the
>> opcache is disabled.  Someone filed a piwik bug but was told it's a
>> php bug:
>>
>> http://dev.piwik.org/trac/ticket/4093
>>
>> - Grant
>
> Is this a known issue?
>
> - Grant

Is there anything I can do?

- Grant

--- End Message ---

Reply via email to