php-general Digest 1 Jun 2013 20:25:12 -0000 Issue 8255

Topics (messages 321302 through 321309):

Re: Looking for a good working PDO and/or mysqli database class to get started 
with OOP
        321302 by: dealTek

Binding object instances to static closures
        321303 by: Nathaniel Higgins
        321305 by: David Harkness
        321306 by: Nathaniel Higgins
        321307 by: Nick Whiting
        321308 by: David Harkness

Re: mcrypt_create_iv - why so slow?
        321304 by: Matt Graham

How to enable cURL php extension on Debian Wheezy?
        321309 by: Csanyi Pal

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 May 30, 2013, at 7:30 PM, tamouse mailing lists <tamouse.li...@gmail.com> 
wrote:

> Sounds like the OP is asking for a pre-built CRUD interface that
> adapts to his tables and their relationships. It's a fair question,
> just one I don't have an answer to. There must be some kind of ORM for
> PHP?




Thanks tamouse - that is what I was trying to ask about...

Thanks Bastien for the suggestions...
Propel? Eloquent? Doctrine?

Do any of the ones  listed below the email seem like a good start?

Q: DOES ANYONE HAVE ANY OPINIONS ON THE ONES BELOW?

- - - - - MySQLi

https://github.com/ajillion/PHP-MySQLi-Database-Class

http://www.phpclasses.org/package/2359-PHP-MySQL-database-wrapper-using-MySQLi-extension.html

http://snipplr.com/view/22992/

Jeffrey Way...
http://forrst.com/posts/Mysqli_Database_Class-hxb

http://www.dotred.be/blog/database-classes-for-mysql-mysqli-and-mssql/

- - - - - PDO

Jeffrey Way - some issues here in comments
http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/

http://www.phpclasses.org/package/7533-PHP-Access-SQL-databases-using-PDO.html

http://www.doctrine-project.org/projects/dbal.html

http://pear.php.net/package/MDB2


--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-3]


--- End Message ---
--- Begin Message ---
Is it possible to bind an instance to a static closure, or to create a
non-static closure inside of a static class method?

This is what I mean...


    <?php
    class TestClass {
        public static function testMethod() {
            $testInstance = new TestClass();
            $testClosure = function() use ($testInstance) {
                return $this === $testInstance;
            };

            $bindedTestClosure = $testClosure->bindTo($testInstance);

            call_user_func($bindedTestClosure);
            // should be true
        }
    }

    TestClass::testMethod();

--- End Message ---
--- Begin Message ---
On Fri, May 31, 2013 at 10:54 AM, Nathaniel Higgins <n...@nath.is> wrote:

> Is it possible to bind an instance to a static closure, or to create a
> non-static closure inside of a static class method?
>

PHP doesn't have a method to do this. In JavaScript you can use jQuery's

    var func = $.proxy(function () { ... }, object);

In fact, you cannot use $this inside a closure at all (unless 5.4 has added
a way that I haven't seen yet). You can get around that by declaring a
local variable to hold a reference to the instance to use with "use". It
looks strange here because you're also passing in $testInstance for the
comparison.

    <?php
    class TestClass {
        public static function testMethod() {
            $testInstance = new TestClass();
            $closure = $testInstance->createClosure($testInstance);

            call_user_func($closure);
            // should be true
        }

        private function createClosure($testInstance) {
            $self = $this;
            return function() use ($self, $testInstance) {
                return $self === $testInstance;
            }
        }
    }

    TestClass::testMethod();

Peace,
David

--- End Message ---
--- Begin Message ---
I'm talking about PHP 5.4. `bindTo` is a Closure method in PHP 5.4, and
allows you to set the `$this` variable inside of a Closure. However,
apparently you can't use it on Closures created inside static methods.

I knew that you could create another function which would return the
Closure, however, that isn't what I asked. I wanted to either use the
`bindTo` method on a static Closure, or create a non-static Closure in a
static method.


On 31 May 2013 19:25, David Harkness <davi...@highgearmedia.com> wrote:

> On Fri, May 31, 2013 at 10:54 AM, Nathaniel Higgins <n...@nath.is> wrote:
>
>> Is it possible to bind an instance to a static closure, or to create a
>> non-static closure inside of a static class method?
>>
>
> PHP doesn't have a method to do this. In JavaScript you can use jQuery's
>
>     var func = $.proxy(function () { ... }, object);
>
> In fact, you cannot use $this inside a closure at all (unless 5.4 has
> added a way that I haven't seen yet). You can get around that by declaring
> a local variable to hold a reference to the instance to use with "use". It
> looks strange here because you're also passing in $testInstance for the
> comparison.
>
>     <?php
>     class TestClass {
>         public static function testMethod() {
>             $testInstance = new TestClass();
>             $closure = $testInstance->createClosure($testInstance);
>
>             call_user_func($closure);
>             // should be true
>         }
>
>         private function createClosure($testInstance) {
>             $self = $this;
>             return function() use ($self, $testInstance) {
>                 return $self === $testInstance;
>             }
>         }
>     }
>
>     TestClass::testMethod();
>
> Peace,
> David
>
>


-- 
Thanks,
http://nath.is
@NatIsGleek <http://twitter.com/natisgleek>
-- --
Unless otherwise specified, this conversation can be classed as
confidential, and you have no permission to share all, part, or even the
gist of this conversation with anyone not part of the original
conversation. If in doubt, please contact be with the above links, or on my
UK phone number - *07427558947*. Please be thoughtful of what time it is in
the UK at your time of calling.

--- End Message ---
--- Begin Message ---
This will not work.

As stated in the PHP documentation "Static closures cannot have any bound
object "

A static Closure has no context of "this" just as with any other static
object.

A workaround is to pass in the Closure as a parameter to achieve a similar
result.

class TestClass {
    public static function testMethod($function) {
        $testInstance = new TestClass();
        $function = $function->bindTo($testInstance);
        call_user_func_array($function, [$testInstance]);
        // should be true
    }
}

TestClass::testMethod(function($param){
    var_dump($this === $param);
});


On Fri, May 31, 2013 at 2:32 PM, Nathaniel Higgins <n...@nath.is> wrote:

> I'm talking about PHP 5.4. `bindTo` is a Closure method in PHP 5.4, and
> allows you to set the `$this` variable inside of a Closure. However,
> apparently you can't use it on Closures created inside static methods.
>
> I knew that you could create another function which would return the
> Closure, however, that isn't what I asked. I wanted to either use the
> `bindTo` method on a static Closure, or create a non-static Closure in a
> static method.
>
>
> On 31 May 2013 19:25, David Harkness <davi...@highgearmedia.com> wrote:
>
> > On Fri, May 31, 2013 at 10:54 AM, Nathaniel Higgins <n...@nath.is> wrote:
> >
> >> Is it possible to bind an instance to a static closure, or to create a
> >> non-static closure inside of a static class method?
> >>
> >
> > PHP doesn't have a method to do this. In JavaScript you can use jQuery's
> >
> >     var func = $.proxy(function () { ... }, object);
> >
> > In fact, you cannot use $this inside a closure at all (unless 5.4 has
> > added a way that I haven't seen yet). You can get around that by
> declaring
> > a local variable to hold a reference to the instance to use with "use".
> It
> > looks strange here because you're also passing in $testInstance for the
> > comparison.
> >
> >     <?php
> >     class TestClass {
> >         public static function testMethod() {
> >             $testInstance = new TestClass();
> >             $closure = $testInstance->createClosure($testInstance);
> >
> >             call_user_func($closure);
> >             // should be true
> >         }
> >
> >         private function createClosure($testInstance) {
> >             $self = $this;
> >             return function() use ($self, $testInstance) {
> >                 return $self === $testInstance;
> >             }
> >         }
> >     }
> >
> >     TestClass::testMethod();
> >
> > Peace,
> > David
> >
> >
>
>
> --
> Thanks,
> http://nath.is
> @NatIsGleek <http://twitter.com/natisgleek>
> -- --
> Unless otherwise specified, this conversation can be classed as
> confidential, and you have no permission to share all, part, or even the
> gist of this conversation with anyone not part of the original
> conversation. If in doubt, please contact be with the above links, or on my
> UK phone number - *07427558947*. Please be thoughtful of what time it is in
> the UK at your time of calling.
>



-- 
Nickolas Whiting
Lead Developer
X Studios
321-281-1708x107

--- End Message ---
--- Begin Message ---
Thanks Nathaniel for the clarification about 5.4. We are still on 5.3 (and
that only recently), so 5.4 is a ways off in our production systems.
However, I'll read up on this since it may be useful in offline tools.

On Fri, May 31, 2013 at 11:52 AM, Nick Whiting <nwhit...@xstudiosinc.com>wrote:

> TestClass::testMethod(function($param){
>     var_dump($this === $param);
> });
>

I get why closures created inside static methods cannot be bound to an
instance . . . but those created *outside* an object method entirely *can*
be bound? That makes no sense! And yet it works.

David

--- End Message ---
--- Begin Message ---
From: Nathan Nobbe
> Interesting, using MCRYPT_DEV_URANDOM instead of MCRYPT_DEV_RANDOM
> seems practically instantaneous. Still [raises] the question though,
> any idea what's holding up the show w/ MCRYPT_DEV_RANDOM?

/dev/random is a high quality entropy source and requires more time to
generate output, as it has to retrieve random stuff from keyboard interrupts,
mouse interrupts, and other sources, and make sure it's got *really* random
bits.  /dev/urandom will just throw out a pile of pseudo-random bits of
potentially lower quality immediately.  You can see that by doing "time dd
if=/dev/random of=/dev/null bs=16k count=5" and repeating the same command
with /dev/urandom.  1.312 seconds vs. 0.019 seconds here.

Not much to do with PHP, though, just the way the Linux kernel people did
things.  /dev/urandom is probably the way to go for most normal random data
needs.

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


--- End Message ---
--- Begin Message ---
Hi,

I just upgraded Squeeze to Wheezy, and have difficulties with cURL PHP
extension: I can't enable it.

I have installed following packages related to this issue:
curl, libcurl3, libcurl3-gnutls, php5-curl.

I have in
/etc/php5/mods-available/curl.ini
; configuration for php CURL module
; priority=20
extension=curl.so

I know that cURL extension is not enabled because I want to install
Moodle and it complains about cURL extension.

How can I solve this problem?

-- 
Regards from Pal


--- End Message ---

Reply via email to