SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 56
  1. #26
    SitePoint Addict n0other's Avatar
    Join Date
    Feb 2005
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, what's wrong with empty() ? Only drawback I see in it is that it treats variable containing zero as an empty one. I use it to check arrays pulled from db before looping through them.

  2. #27
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony Marston
    If underscores are easier to read then they should always be the first choice.
    No they shouldn't.

  3. #28
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    function wtf($pos)
    {
    echo '<pre>';
    var_dump($pos);
    echo '</pre>';
    }
    Now that I am going to use....

    Now, can what suggestions have we for the functionality encapsulated in rtfm() ?

  4. #29
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paulyG
    Now that I am going to use....

    Now, can what suggestions have we for the functionality encapsulated in rtfm() ?
    That's easy!
    Code:
    echo(file_get_contents("http://www.google.com?q=$_GET[wtf]"));

  5. #30
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hardehah...

    I think you mean a recursive function so:

    //pseudo code

    function rtfm($add,$wtf){

    foreach( link on page ){
    file_get_contents( "http://www.google.com?q=".$wtf )
    db->open()
    db->store()
    }

    $db->prepare("select * from rtfm where daydate>0 limit 3000000")
    $db->execute();
    while($c = $db->fetch()){
    mail($add,"OI! you dumb ****, RTFM!",$c->page_contents);
    }
    }

    //usage
    $a="yossarian@catch22.com";
    $wtf="array";
    rtfm($a,$wtf);

  6. #31
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Within such a function, I think calls to lart and luser are warranted.

  7. #32
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Sutton, Surrey
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Commander Cobra
    Quote Originally Posted by Tony Marston
    If underscores are easier to read then they should always be the first choice.
    No they shouldn't.
    So you like writing code that is less readable? How very un-cool.

  8. #33
    SitePoint Member
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Commander Cobra
    Related to function names, I've done some incredibly deep thinking about underscores vs. studly caps:

    functionName - 13 keystrokes
    function_name - 14 keystrokes

    Therefore I like studly caps best from a laziness perspective, but I think underscores are easier to read.
    Actually, that's not correct. You'll have to press shift to get that capital N, which results in (yes!) 14 keystrokes
    ://phoop.net
    Home of the Papercut Template Engine - latest release 0.9.3alpha

  9. #34
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Nezzar
    Actually, that's not correct. You'll have to press shift to get that capital N, which results in (yes!) 14 keystrokes
    Wrong.

    f1u2n3c4t5i6o7n8N10a11m12e13

    13 keystrokes.

  10. #35
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony Marston
    So you like writing code that is less readable? How very un-cool.
    LOL, guess you've never coded in Perl. Doesn't matter what you think, seeing how you use MySQL - standards don't matter to you. And if the readability of underscores vs. studlycaps is so vastly different to you, go see an eye doctor.

  11. #36
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Sutton, Surrey
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Commander Cobra
    ... if the readability of underscores vs. studlycaps is so vastly different to you, go see an eye doctor.
    Only if you go see a proctologist

  12. #37
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    RS, Brazil
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the worst function is require(). It's there just to make errors like "redeclare class bla bla bla"! There should be only require_once() .

    the least useful is array_push. Why not use $arr[] = 1; instead?

  13. #38
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Nezzar
    Actually, that's not correct. You'll have to press shift to get that capital N, which results in (yes!) 14 keystrokes
    I thought so, too, 'till realized that underscore takes a shift-stroke too! Dooh!

    Quote Originally Posted by coo_t2
    I think the original poster is talking about PHP's built-in functions, correct?
    How to define "built-in" - I know there are "core" functions, but aren't most functions add-ins?

    From the reserved words list (some aren't functions):
    array() die() echo() empty() exit() include() include_once() isset() list()
    print() require() require_once() return() unset()

    Is this just semantics?

  14. #39
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tony Marston
    Only if you go see a proctologist
    I don't need to - I don't abuse that part of my body, unlike you.

  15. #40
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigodines
    the worst function is require(). It's there just to make errors like "redeclare class bla bla bla"! There should be only require_once() .

    the least useful is array_push. Why not use $arr[] = 1; instead?
    PHP hackers - like Rasmus Lerdorf - don't like require_once (and include_once I presume). Use enough of them and performance can be affected (not much really). Not worth worrying about I say - I consider include_once and require_once better coding.

  16. #41
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Commander Cobra
    PHP hackers - like Rasmus Lerdorf - don't like require_once (and include_once I presume). Use enough of them and performance can be affected (not much really). Not worth worrying about I say - I consider include_once and require_once better coding.
    As far as I can see, you have to keep require() and include() because of when you want to include() or require() in a local scope.
    If you inclue_once() or require_once() in a local scope then you're SOL if you want to require(_once)() or include(_once)() the same file from a different scope.

  17. #42
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand - you mean in functions? I use include_once there.

  18. #43
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Run this code:

    PHP Code:
      
      <?php
      
      
    // File name: scopeTest.php
      
      
    error_reporting(E_ALL);
      
      function 
    test1()
      {
          include_once(
    './testInclude.php');
      
          echo 
    'var_dump($testIncludeVar) in test1() = ';
          
    var_dump($testIncludeVar);
          echo 
    "\n\n";
      
      }
      
      function 
    test2()
      {   
          include_once(
    './testInclude.php');
      
          echo 
    'var_dump($testIncludeVar) in test2() = ';
          
    var_dump($testIncludeVar);
          echo 
    "\n\n";
      }
      
      
      
    test1();
      
    test2();
      
      
      
      
    ?>
      
      
      <?php
      
      
    // File name: testInclude.php
      
      
    $testIncludeVar 'this is $testIncludeVar';
      
      
    ?>
    I ran this on PHP5 but I've ran into the same problem on PHP4.

    What's strange is if you use include_once() in the first function and just include() in the second function it works ok, but if you use
    include() in the first function and include_once() in the second it doesn't work, if you use
    include_once() in both it doesn't work.

    This is just a simple example, I never include files with "naked" variables, the files I include are
    almost always classes or config files with defined constants, but the same problem exists.

    If I have a method in a class or object that wants to conditionally include/require another file
    I have to use require() or include() or that file won't be available in another scope. The only other
    option I can think of is just to include_once() or require_once() the file in the global scope
    whether I'm sure I'm gonna need it or not.

    This seems like such a basic problem that I've always thought I must be having a mental block and
    overlooking something. Am I?

  19. #44
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, never heard of that. One workaround is to use 'global $textIncludeVar' in the functions. But I never use globals...

    BTW, is there any reason to prefix included/required files with './'?

  20. #45
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Commander Cobra
    BTW, is there any reason to prefix included/required files with './'?
    No. I do it sometimes in little scripts or test scripts if the file is in the cwd. Not sure why. Just a way to be more explicit, I guess.

  21. #46
    Non-Member Commander Cobra's Avatar
    Join Date
    Sep 2005
    Location
    us
    Posts
    271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coo_t2
    No. I do it sometimes in little scripts or test scripts if the file is in the cwd. Not sure why. Just a way to be more explicit, I guess.
    Actually, IIRC, it might cause PHP to avoid looking in the include_path. But PHP looks first in cwd first though (in which case there probably isn't any performance benefit).

  22. #47
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Commander Cobra
    Actually, IIRC, it might cause PHP to avoid looking in the include_path. But PHP looks first in cwd first though (in which case there probably isn't any performance benefit).
    I think sometimes I start doing something for a reason and then over time I forget why, I just do it because it has become habit. So that might of been the origin, although you're probably right about there being no performance benefit.

  23. #48
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by n0other
    Heh, seems like somebody here needs an editor with autocompletion feature
    true , but then you'll still need to type it once. At least I do in Vim.
    It's not a function but I find the $_POST and $_GET arrays a bit long to time and make your code ugly (imho).
    Just a $_P or $_G would do.

  24. #49
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  25. #50
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Sutton, Surrey
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Commander Cobra
    Quote Originally Posted by Tony Marston
    Only if you go see a proctologist
    I don't need to - I don't abuse that part of my body, unlike you.
    But you tend to talk out of it a lot.


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
  •