php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11567 True Dynamic Binding and Public/Private
Submitted: 2001-06-19 15:10 UTC Modified: 2002-04-27 15:34 UTC
From: Mike dot Eggleston at michaelsmacshack dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.5 OS: Linux
Private report: No CVE-ID: None
 [2001-06-19 15:10 UTC] Mike dot Eggleston at michaelsmacshack dot com
Ok Folks.  I am really happy with PHP thus far.  However to make it a true Object Oriented Language you absolutly need Dynamic binding.  This would be such a huge boon for us developers who love to work within classes.  Such as:

// Inside the class Circle

function DrawMe() {
    // Getting Ceter Coords..
    DrawMe($centX, $centY);
}

function DrawMe($x, $y) {
    // Draws the circle at $x, $y
}

// End of code demo

This kind of ability can be extremely huge, if you use it right.  Also, it allows for developers to make a module extremely flexiable and powerful.

Secondly, I think that we are missing public and private sections of the OOP world.  In the above example, I would have the functions public, and the data structures inside of it totally hidden (or private) so the programmer who is using my include just has to deal with the interface, and can't touch the actual data.  That is strength and beauty of encapsulation.

I just thought you may want to hear this, and I am hoping to hear from you guys (and gals) that you are hard at work to implement it and it is coming soon.

Thanks for reading my rant!!

Mike Eggleston
AmeriGroup
Mike.Eggleston@michaelsmacshack.com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-19 22:05 UTC] cynic@php.net
function drawMe()
{
    if( 2 == func_num_args() ) {
        doStuff( func_get_arg(0) , func_get_arg(1) ) ;
    } else {
        doStuff( $defaultX , $defaultY ) ;
    }
}

private vars/methods would be good... :)
 [2001-06-20 00:42 UTC] rasmus@php.net
I completely disagree with the concept of dynamic binding.
Calling different functions based on the number of arguments
is spaghetti code waiting to happen.  PHP supports default
values for arguments which makes them optional.  Your 
would be much cleaner if written with defaulted x and y 
arguments which you then check and if you have the default
value for x and/or y you would calculate the center value.
Or alternatively use func_num_args to see how many args were
passed.  To me it is cleaner to collect the functionality for a function in a single function instead of splitting it 
out over multiple functions.  Imagine trying to debug some
code and you end up looking at the wrong function just
because you counted 17 arguments instead of 18.

As for the public/private issue.  Sure, from an OO purity
perspective it would be nice.  But it is functionally irrelevant.  ie. your code would not work any better or
worse by having the public/private differentiation.
 [2001-06-20 11:54 UTC] Mike dot Eggleston at michaelsmacshack dot com
I disagree with your comment on how dynamic bindings are used.  The whole purpose of dynamic binding is give a function whose purpose could be asked for in many different ways yet is asking to do the same thing the ability to hide how it works from the programmer using it.  In C++, there is a function of exp, which could be sent four different methods:

int exp (int base, int exponent)
double exp (int base, double exponent)
double exp (double base, int exponent)
double exp (double base, double exponent)

If anything, it makes the programmers job easier to utilize this function because they only have to remember ONE function, not four different ones accomplishing the same task.

Admittedly, PHP doesn't have data types in the traditional sense, however it should have Dynamic Binding because one of the most fundamental rules of Object Oriented Programming is the idea of hiding the how and just utilizing the functions and classes.

The same argument can be made for the public/private distinction.  Adding this feature is an excellent way to make sure that programmers do not mess with the logical code that you worked so hard on.  Also, it forces programmers to use the functions of the class, as the orginal programmer percieved it.

I want to see PHP become the best Web Programming Language out there, and proper OOD techniques is fundamental to getting there.
 [2002-04-27 15:34 UTC] jimw@php.net
multiple dispatch is not going to happen. ZE2 has private member values.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 03:01:28 2024 UTC