Jump to content

Hall of Famer

Members
  • Posts

    314
  • Joined

  • Last visited

Posts posted by Hall of Famer

  1. use \Model\User\Member as Member;
    use \Model\User\Admin as Admin;
    use \Model\User\Banned as Banned;
    use \Model\User\Guest as Guest;

     

    LOL

     

    1) The as Class part is redundant

    2) Why would you create a class for each user role?

    3) Assuming all of them implement a UserInterface, how would you check if you are dealing with a banned user?

     

    if ($user instanceof Banned) {

     

    Which is:

     

    1) Not flexible and also hard-couples your code to an implementation

    2) If at some point you wish to create a PrivilegedMember you will have to hunt down all type checking code

    and add it.

    3) It's error prone, for example if PrivilegedMember extends Member type checking like this:

     

    if ($user instanceof Member) {
     // ..
    } else if ($user instanceof PrivilegedMember) {

     

    Means a privileged member is no longer so privileged.

     

    4) It's boring. A new type means lots of code changes as does privilege changes.

    Instead use roles, resources, and privileges:

     

    if ($this->acl->isAllowed($this->user, 'content', 'edit')) {

     

    Banned is not a role, more a state, since anyone can be banned, afterwards you still have to know what role he has/had, and it can have special behavior like being only temporary. Something that is not easily captured in an ACL

     

    if ($user->isBanned()) {
     $this->redirect()->to('/you-are-banned');
    }

     

    Well I am just using this as a quick example in which you may have a series of classes from a namespace you wish to import quickly into another namespace. And now you spent an hour writing useless criticism just for explaining how that user system aint working, its completely missing the point I was arguing early on.

  2. Because this is PHP and not Java :P

     

    But its a really useful feature PHP is missing, not like the syntax which is simply a matter of opinion. Assume you have a UserFactory class to decide which type of user object(Member, Admin, Banned and Guest) to instantiate, all of these user classes are in the subpackage Model\User. You will have to write this many lines in PHP:

    use \Model\User\Member as Member;
    use \Model\User\Admin as Admin;
    use \Model\User\Banned as Banned;
    use \Model\User\Guest as Guest;
    

     

    In java, all you have to do is to write this line:

    import Model.User.*
    

     

    See how life can be made easier? Sure it may not seem to be a problem when you only needs to import one namespace with four classes, but what if in your controller class you have to import like 5 namespaces and 30+ classes? It will be quite a mess I must say.

     

    PHP requires you to be explicit. That's not necessarily a bad thing. For example, if you can import wildcard namespaces:

     

    Yeah at times it may be helpful, but you have to agree that its so inflexible. There are more occasions you need to import multiple classes from a namespace than dealing with conflicting class names, and PHP aint good at handling this since you can only import one class at a time.

  3. Well its been a while since PHP added namespace support, but so far its still crappy. I am not sure if this has been changed in PHP 5.5, but at least in 5.3.18 and 5.4.9 you cannot do this:

     

    namespace A{
    class Foo{
     public function bar(){
    	 echo "foo bar";
     }
    }
    }
    
    namespace B{
    use \A;
    $a = new Foo();
    $a->bar();
    // This results in a fatal error!
    }
    

     

    Instead, you either have to use the whole namespace name or just import classes in a package one by one:

     

    namespace B{
     $a = new \A\Foo;
     $a->bar();
     // outputs foo bar;
    
     use \A\Foo;
     $n = new Foo;
     $n->bar();
     // outputs foo bar;
    }
    

     

    This results in a serious problem when you wish to import an entire sub-namespace. In a real application its unlikely you only have one Foo class in the namespace A, so you have to write multiple lines of use statement to import all these classes, which can be quite annoying.

     

    You may argue that Aliasing is here to serve the purpose, but honestly aliasing is only useful in a really complicated system with namespace as long as 'Application\Model\User\Member\Profile\ProfileField\AboutMe'. In most occasions aliasing is just as much typing as using the entire namespace name, and serves no practical purpose.

     

    You know in Java you can import a package of class using something like 'import javax.swing.*', no idea why in PHP its not possible. Or maybe its already available in PHP 5.5? I dunno.

  4. Well if you have strong programming background in other languages in C++, Java or C#, it shouldnt take more than 3 weeks for you to grasp PHP. If you indeed are, I have to warn you that PHP is not as much object-oriented as these, so some old habits need to change.

  5. This is a diffucult and one that I had to deal with not too long ago. For myself, any new PHP application I code requires PHP 5.3+. Anything that users currently use, I try not to bring the majority at a disadvantage.

     

    Well actually many webhosts such as HostGator and Bluehost already enable PHP 5.3 as an option for users, although the default version is still PHP 5.2.17. Users can edit or add a line in config file to use PHP 5.3. For freehosts you cant really help, some do not even have a working PDO lol.

  6. Well I am designing a software to be used by many users who may have freehosts, sharedhosts or VPS. There are some awesome features only available in PHP 5.3 I want to use for my softeare, such as namespace and about 80% of DateTime methods. A problem is that a few users still have hosting packages that run with PHP 5.2.17, but I wonder if it is about time to drop support for these PHP 5.2 users? I mean, is it a good practive to require users to have PHP 5.3+ on their server for application design nowadays? What do you think?

  7. I'm amateur in PHP but not in Programming. I'm programmer in MEL script, a branch of C++ in Animation and Visual Effects. Now I have no problem in using OOP in my project, that's the reason I asked it. Thanks

     

    No worries, if so I am more than certain that you should be using OOP, a non-amateur programmer should be fine with OOP and should stick to it. PHP is much more similar to Java and C#, although C++ is not that much different. Can be a bit tricky if you are so used to using friend classes/properties/methods though.

  8. Yes exactly...But read my post, I told this is my first web experience..so it means that I want to know more about methods being employed these days

     

     

    akphidelt2007

     

    That is my own web and I am going to establish a CMS.

     

    Well if this is your first time into web development, you'd probably want to start off with procedural programming unless you really know what you are doing with PHP. I do recommend you to learn OOP while developing your site, since it is one huge step for amateurs to turn into professionals. Someday you may want to go full OO once you are good at it, and that your site gets bigger and more complex. Good luck, theres always enough to learn in the world of programming.

  9. But what about arguments, where do they come from? Would they have to be argument-less objects only? How often do you create an object that doesn't have arguments? Seems like it would be a lot of changes for something that doesn't really serve much use, or make a lot of sense.

     

    umm why? I do not see this is a problem. You pass whatever parameter into the object as you want. It works out with not only object without arguments, but also situations in which your arguments are integers, strings or boolean values. An example is given below:

     

    class Foo{
    public $string;
    private $integer;
    public function __construct($str, $int){
     $this->string = $str;
     $this->integer = $int;
    }
    public function getInt(){
     return $this->int;
    }
    }
    class Bar{
    public $foo = new Foo("This is a string", 1);
    public function print(){
     echo $this->foo->string;
     echo "<br>";
     echo $this->foo->getInt();
    }
    }
    $bar = new Bar;
    $bar->print();
    // prints "This is a string" in line 1, and "1" in line 2.
    

     

    Well yeah, it can get tricky if your object properties need variable arguments, it can also be achieved using dependency injection.

  10. Surprised that I did not come across a discussion thread here, so I decide to bring one up.

     

    PHP 5.5.0 Alpha1 released

     

    15-Nov-2012

     

    The PHP development team announces the immediate availability of PHP 5.5.0alpha1. This release marks the beginning of the PHP 5.5.0 release cycle. All users of PHP are encouraged to test this version carefully' date=' and report any bugs in the bug tracking system.THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION!

    PHP 5.5.0 Alpha 1 comes with new features such as (incomplete list) :

    • support for Generators,
    • a new password hashing API,
    • support for finally in try/catch blocks
    • support for list() in foreach,
    • constant array/string dereferencing,
    • ext/intl improvement.

    We also dropped support for Windows XP and 2003.

    You can read the full list of changes in the NEWS file contained in the release archive.

    For source downloads of PHP 5.5.0 Alpha 1 please visit the download page, Windows binaries can be found on windows.php.net/qa/.

    Thank you for helping us making PHP better.

     

    Looks like lots of solid additions, although it does not look as exciting as PHP 5.3 and 5.4's initial releases. Whats your thought? I was expecting syntax like this below to be made possible in PHP 5.5, too bad its not happening and we still have to use the constructor to initiate properties as objects:

     

    class Foo{
    }
    class Bar{
    public $foo = new Foo();
    }
    

  11. Of course OOP, unless you are building an amateur fan site. OOP is the standard for quality programming, and since your site actually has online-payment Id say you will need such professionalism. In a perfect script everything is an object. You cannot be perfect, but you can approach as close as you can.

  12. Well if all your script does is to output one line of sentence to your users such as echo "hello world", or echo "Welcome to our site", then why not just use plain html? XD

  13. It just annoys me that there's a facebook plugin but they don't support composite foreign keys. Get data modeling right before you start doing extra crap.

     

    There's also a LOT of file bloat. Every database table is represented by SIX PHP classes, many of them empty. In order to add a custom setter to a file, you have to open at least 3 more so you make sure you're hitting all the right functions. And forget about trying to load symfony in something like Zend which will try to scan the project file for autocomplete information, there's too many objects.

     

    The fact that it loads every translation file on the entire site every time you load anything bothers me too. The overhead is ridiculous, nothing is compartmentalized. Each "bundle" is not necessarily self-contained, everything is in the global scope to the symfony app. In contrast to this, everything is heavily namespaced, so you need to import a dozen classes before you can do anything useful in a controller, but other things like translations and template files are automatically global with no importing necessary. Silly.

     

    lol are you sure about this? In my application each database table has one class that wraps the data and performs certain actions, I thought it was already way too much. Six sounds like an overkill to me, but perhaps Symfony has them for different uses?

  14. Well in my application the private message database table stores the following info:

     

    mid: Message ID

    sender: The sender's info

    recipient: The recipient's info

    title: Message Title

    text: Message Context

    datesent: The date message is sent

    status: Unread or Read(users are notified by unread messages from a widget at sidebar)

    folder: The folder a private message is stored in. Can be Inbox, Outbox, Draft or user created folders

     

    So yeah, it really depends on how complex your PM system is gonna be. You can start off with a simple design, but make sure it is extensible and reusable so you can add new features every now and then. If you have other types of messages such as Visitor Message(profile comment), Shoutbox Message and System Message, it will be a good idea to use strategy design pattern.

  15. Yeah, it is perhaps not even necessary to worry about PHP 5.2 compatibility nowadays. PHP 4 was great while it lasted, but now it's totally out of date.

     

    Most popular frameworks do take care of 3rd party modules integration pretty nicely, although they do it in a quite different way. The aspect of third party script integration is not that important for framework selection, but that's just my opinion.

  16. Well PHP is still the most popular web programming language at this point. It is relatively easy to learn for beginners, and its syntax is similar to C++/Java so those who have desktop application development find it easier to get used to PHP. Not mentioning PHP is specialized to code in dynamic web pages. So yeah, there is a reason why PHP is popular and will be popular.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.