Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-16 Thread David Harkness
On Sun, May 15, 2011 at 3:15 PM, Richard Quadling wrote:

> Personally, I would recommend using 1 naming convention and sticking with
> it.
>

I wholeheartedly agree. Multiple method names is not flexibility--it's
confusion and an open invitation for bugs. Plus, even with two styles you'll
never satisfy everyone. For example I would expect getNumRows() or
getRowCount().

David


Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Richard Quadling
On 15 May 2011 23:06, Andre Polykanine  wrote:
> Hello Richard,
>
>      I'd  like  to  make  a database wrapping class (yet another one,
> aha!) as flexible, as possible.
> So I'd like to make possible to call, for example,
> $db->num_rows($result)
>                     and
> $db->NumRows($result)
> And was just wondering :-).
>
> --
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> My blog: http://oire.org/menelion (mostly in Russian)
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion
>
>  Original message 
> From: Richard Quadling 
> To: Andre Polykanine
> Date created: , 12:48:30 AM
> Subject: [PHP] Functions/methods aliases in PHp 5.2
>
>
>      On 15 May 2011 21:45, Andre Polykanine  wrote:
>> Hi everyone,
>>
>> Is there any possibility to make a method or function alias in PHP?
>> Yes, I know I can do the following:
>>
>> > function foo_bar($x) {
>> // And so we code...
>> return $result;
>> }
>>
>> function FooBar($x) {
>> return foo_bar($x)
>> }
>>
>> But maybe there is a more elegant solution?
>> Thanks!
>
> Whilst you can do class_alias() - something I use to hide the long
> class name for soap services - there isn't a function alias.
>
> But, if you are creating your own functions, then you could use a
> closure and that can be assigned to a variable ...
>
> $fn_FooBar = function() { ... };
>
> $fn_FooBar($a, $b, $c);
>
> or
>
> someFunc($fn_FooBar) { ... }
>
>
> Closures are ideal for callbacks.
>
> Why do you want to alias functions? Is it to obscure the existing name?
>
> If so, take a look at using an encoder. This uses the compiled code
> rather than the source to run.
>
> It is faster to run as there is no compile phase and the "code" isn't
> very easy to reverse.

A couple of things come to mind.

1 - If you create a subclass and were overriding num_rows(), the
subclass would have to also override NumRows(). Twice as much work.

2 - You could use __call() and __callStatic() magic methods, but you'd
have limited options for documentation then (assuming you use
docblocks.

Personally, I would recommend using 1 naming convention and sticking with it.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Andre Polykanine
Hello Richard,

  I'd  like  to  make  a database wrapping class (yet another one,
aha!) as flexible, as possible.
So I'd like to make possible to call, for example,
$db->num_rows($result)
 and
$db->NumRows($result)
And was just wondering :-).

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

 Original message 
From: Richard Quadling 
To: Andre Polykanine
Date created: , 12:48:30 AM
Subject: [PHP] Functions/methods aliases in PHp 5.2


  On 15 May 2011 21:45, Andre Polykanine  wrote:
> Hi everyone,
>
> Is there any possibility to make a method or function alias in PHP?
> Yes, I know I can do the following:
>
>  function foo_bar($x) {
> // And so we code...
> return $result;
> }
>
> function FooBar($x) {
> return foo_bar($x)
> }
>
> But maybe there is a more elegant solution?
> Thanks!

Whilst you can do class_alias() - something I use to hide the long
class name for soap services - there isn't a function alias.

But, if you are creating your own functions, then you could use a
closure and that can be assigned to a variable ...

$fn_FooBar = function() { ... };

$fn_FooBar($a, $b, $c);

or

someFunc($fn_FooBar) { ... }


Closures are ideal for callbacks.

Why do you want to alias functions? Is it to obscure the existing name?

If so, take a look at using an encoder. This uses the compiled code
rather than the source to run.

It is faster to run as there is no compile phase and the "code" isn't
very easy to reverse.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



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



Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Richard Quadling
On 15 May 2011 21:45, Andre Polykanine  wrote:
> Hi everyone,
>
> Is there any possibility to make a method or function alias in PHP?
> Yes, I know I can do the following:
>
>  function foo_bar($x) {
> // And so we code...
> return $result;
> }
>
> function FooBar($x) {
> return foo_bar($x)
> }
>
> But maybe there is a more elegant solution?
> Thanks!

Whilst you can do class_alias() - something I use to hide the long
class name for soap services - there isn't a function alias.

But, if you are creating your own functions, then you could use a
closure and that can be assigned to a variable ...

$fn_FooBar = function() { ... };

$fn_FooBar($a, $b, $c);

or

someFunc($fn_FooBar) { ... }


Closures are ideal for callbacks.

Why do you want to alias functions? Is it to obscure the existing name?

If so, take a look at using an encoder. This uses the compiled code
rather than the source to run.

It is faster to run as there is no compile phase and the "code" isn't
very easy to reverse.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



[PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Andre Polykanine
Hi everyone,

Is there any possibility to make a method or function alias in PHP?
Yes, I know I can do the following:

http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion


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