SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Stillwater, MN
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Abstraction of basic PHP features?

    Over at another forum, I looked at a thread containing a File class which basically was a copy of a lot of PHP file functions, and it seems to me that basic abstraction like that isn't really needed and just makes things complicated.
    Code:
    class fileinfo
    {
        function fileinfo($fname = NULL);
        function getLastAccess();
        function getLastModified();
        function getPermission();
        function getSize();
        function getType();
        function getFreeSpace();
        function getTotalSpace();
        function getFileName();
        function getDirName();
        function getBaseName();
        function getExtension();
        function isFile();
        function isDirectory();
        function canWrite();
        function canRead();
    }
    
    class file extends fileinfo
    {
        function file($fname = NULL);
        function open($mode = NULL);
        function getHandler();
        function move($dest = NULL);
        function exists();
        function delete();
        function copy($dest = NULL);
        function write($data = NULL);
        function writeLine($data = NULL);
        function setBufferSize($len = NULL);
        function getBuffersize();
        function close();
        function read();
        function getLine($index = NULL);
        function next();
        function reset();
        function isValid();
    }
    
    
    class directory extends fileinfo
    {
        function directory($fname = NULL);
        function create($mode = 0755);
        function delete();
        function exists();
        function getHandler();
        function getDirectories();
        function getFiles();
        function close();
        function move($dest = NULL);
        function setRecursionLevel($lvl = 1);
        function getCurrent();
        function next();
        function reset();
        function isValid();
    }
    I know the fileinfo class isn't really great OOP, but this is what the guy had.

    All of this code seems to add some bloat. What do you guys think?

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't imagine why anyone would want to write a class like that. Maybe a newbie is flexing his newfound OOP muscles.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    New York
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now, wait a second... I have a reason for creating those classes which were mentioned to be not done as it needs to be more abstract and not extremely well thought out yet. Reason number one is logging actions. I like the option to log when a file is open, what was written to it, and other such things if I choose to do so. Reason number two is the custom error handler that I didn't show on the other forum. And maybe it's just me but I prefer doing something like:

    Code:
    $file = new file('wordlist.txt');
    $file->open('r');
    
    for($file->reset();$file->isValid();$file->next()) {
        $db->execute($file->getLine());
    }
    Instead of using the PHP functions directly.

    But maybe that was a bad example. How about the directory iterator that goes through the directories and subdirectories recursively so you can do whatever you want? It does add bloat, but it's not unnecessary.
    viveHosting.com
    Affordable Hosting, Reliable Service

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, my post may not have been well thought out. It all depends on what you're doing with the class as to whether it would be considered bloat or not. If it's being invoked multiple times in perhaps more than one place in the code, doing something like this can be beneficial.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Seattle, Wa
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first off. If you look at any modern language. It has a class structure like this. For instance, in Java and C#, everything is an object. This just merely provides that functionality for PHP. Obviously Radley is a better/smarter develoer then those at Sun/Microsoft and ECMA http://www.ecma-international.org , the care taker of CLR.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Stillwater, MN
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lasnaranjas
    Well, first off. If you look at any modern language. It has a class structure like this. For instance, in Java and C#, everything is an object. This just merely provides that functionality for PHP. Obviously Radley is a better/smarter develoer then those at Sun/Microsoft and ECMA http://www.ecma-international.org , the care taker of CLR.
    It's really pointless to use personal remarks; I don't use PHP that much any more and I guess my bloat trigger went off when I looked at a class that just wrapped a PHP section in a class. Obviously this was for polymorphism, and I didn't realize that at the time for some reason. Shouldn't there be some library out with this kind of stuff so we don't have to rewrite this kind of stuff?

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    New York
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PEAR probably has something like this, but I along with others tend to not like it. I'm currently working on dotarchitect.org. I'm working on this lowlevel stuff once and no more. I call it a framework, some here can argue that it's a library of classes . But whatever it is, I think it's useful.
    viveHosting.com
    Affordable Hosting, Reliable Service


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •