Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. You start out by asking what we think of this new operator (as a side-note, I'm kind of scratching my head about why they are calling it an operator..). You then mention when it was introduced, and how it is strange. You then say that it seems to be "giving you the option to ignore good coding practice, like setting variables as 'global' inside your function, or using 'or die()'..." You clarified by saying you were giving examples of bad programming practice. But the way you said it in your OP, you are giving examples of how it is giving you the option to ignore good coding practice. That's how you wrote it. That's the grammatically correct way of reading what you wrote. So I was confused and asked about it.
  2. Well I mean yeah I can understand how it would go in the same group as those things, filed under "bad practice" (although I still stand by my argument against die being in that category 100% of the time...) but the way he said it made it sound like that goto somehow did those things.
  3. goto is just like the old basic style goto: You mark a certain position in your code with a label. You can then use goto to jump to that position. I don't really see what goto has to do with setting variables to global inside functions or using die?
  4. As mentioned before, there is the ternary operator that is sort of a shorthand version of if..else. There's also the "$this->xxxx" shorthand for OOP. But I can't really think of anything else. Programming languages don't generally have long and short versions of the same thing. If the short version does the exact same thing as the long, there's no reason for the long version to be there. So there really isn't any "shortand" (other than the ones I mentioned, afaik) things, in the sense that you are talking about. But if you look at in a more general sense of "How can I make this chunk of code smaller, more efficient, etc.." there are probably plenty of ways to do that, but it would be specific to the situation. There are plenty of ways to capitalize on what lots of different built-in functions do, what they produce, etc.. I guess overall what I'm trying to say is the built-in functions are the shortcuts, so the more you learn about them, use them, figure out their nuances, etc.. the more you can look at a long piece of code and be like "hey, since abc function does this and xyz function does this other thing, I can combine them in this way to effectively do the same thing as this long chunk of code!" So as for a physical list, I guess the best thing to offer up is to tell you to go to the manual and go down the list of functions. Learn them. Memorize them. Read what they do, what the arguments do, what data types they can take. How they behave depending on what you push to it. Read the user notes for each of them. They are full of "hey, here's a clever thing to do with this!" or "Hey, here's an unexpected behavior from this..." type of posts. And from there, just practice. Go find random pieces of code. Look at it and think about all that info from php.net you just crammed in your head. Figure out what it is that chunk of code is doing and think about if there is an existing function that already does it, or if combining existing functions produce the same result, etc... p.s.- response to your last post since you posted when I was typing this: It is important to understand that a ternary operator is NOT the exact same as if...else. It has certain limitations to it.
  5. is 530pm really the format you are working with? So what happens when it is 123pm or the like? is it 1:23pm? 12:30pm? 12:03pm? You can't accurately regex something like that.
  6. As far as "shorthand" tricks... if you have to ask then you probably shouldn't be using them. I swear, no offense intended. But the reason shorthand tricks have evolved is from people repeatedly doing things and they understand the concept so well that they can take that next step and make a shorthand version of it. But if you skip that process, you are more than likely going to wind up confusing yourself and making some piece of code or whole system that is all ass backwards and broken because you didn't understand what that "shorthand" really meant. For example, I can't tell you how many times on the forums I've seen people try to use the ternary operator because it looks cool, but end up F'ing it up because they don't really understand it, what it and its limitations vs. its fully typed out counterpart.
  7. &$string does not make $string global. It means to pass a variable be reference. For instance, if you have this: function something ($string) { $string = "bar"; } $string = "foo"; echo $string; // output: foo something($string); echo $string; // output : foo You first assign "foo" to $string. You echo it out and it is "foo". You then call your function, passing $string to it. Inside the function, you change the value of $string. You then echo $string again, after the function call. It is still "foo" because the $string inside your function is not the same variable as the $string outside of your function. When you pass something to a function, you are passing a copy of the value "foo" to it. &$string means to pass by reference. What that means, is instead of telling the function to work with its own copy of the value, you want to work with the reference to the original value. So for instance: function something (&$string) { $string = "bar"; } $string = "foo"; echo $string; // output: foo something($string); echo $string; // output : bar In the function argument, since you are specifying it as being passed by reference, any changes to $string inside the function will be to the original value. So when you echo $string out after the function call, it will be "bar". This is not the same as making it global. It's just that in in this situation, it mimics a global variable/basically acts the same way. However, it is important to understand that it is NOT the same as making a variable global. First off, passing a variable by reference does not have to come from the global scope. You can call a function inside another function, passing a variable by reference, and that won't be tied to the global scope. For example: function something (&$blah) { echo $string; // output: <nothing. this variable doesn't exist> $blah = "bar"; } $string = "foo"; echo $string; // output: foo something($string); echo $string; // output : bar As you can see, I passed $string to the function by reference, but I called it a different name in the argument. So when I try to echo $string inside the function, nothing is echoed. So passing by reference does not make something global. It's just that when you are passing by reference from the global scope and you make the argument var name the same as the global scope var name, it just makes it look like it is global. But they still have their own separate namespace, pointing to the same value. 2nd, when you pass something by reference, php still creates a variable name with its own namespace. But it points that new variable to the same location in memory holding "foo" as the original variable. So for example, you could do this: function something (&$blah) { $blah = "bar"; } $string = "foo"; echo $string; // output: foo something($string); echo $string; // output : bar So you see, I pass $string to the function, and in the function argument, I specify it to be passed by reference, but I did not name it $string. I then set $blah to "bar" and as you can see from the 2nd output, $string gets changed to "bar". So a more graphic representation might look like this: Regular variable passing: scope variable value memory address global $string foo 1234 function $string bar 1235 Passing by reference: scope variable value memory address global $string foo 1234 function $string bar 1234 or scope variable value memory address global $string foo 1234 function $blah bar 1234 Or another way of saying it (the more classic way) is to think of a variable as a box with a label on it. The box holds the info and the label is the variable name. So when you pass a variable to a function, you are creating a new box with a new label, that is a copy of the first box. It may or may not have the same label. Contents of box two equal box one, but they are not the same entity. But when you pass by reference, it's like you are adding a 2nd label to the box, instead of creating 2 boxes.
  8. really? Man, I just don't know... doesn't that sort of conflict with I'm just not feelin' it. I don't think those 2 statements can be friends. They just can't seem to get along. Can't share the same mouth. So one of them has to come out of some other hole. Like...your ass? Yeah, I definitely think you're talking out your ass. Not one of those sly stealth farts that come up and assassinate people out of nowhere. That would have been cool. I can respect the sbvd (silent but very deadlies). Failing that, you could have at least been loud and obnoxious. Kind that shake the room, and you know you just ripped a hole in your undies. Nope. not even that. You're one of those saucy creamy sounding farts. Everybody hears it, but it's not really all that impressive. Kind of funny but in a sad way, because everybody knows from the moment it comes out, you're destined to have to go to the little boy's room and change. I bet you're glad your mom always insists on packing a spare set in your backpack! Even IF it has caused more than your fair share of black eyes and taunts. That'll show them! Who's laughing now! I have a FRESH set of undies! Good for you bud, good for you! Hey since you're already mopping, make sure you get over by your desk. I think I see some leakage that got away.
  9. It's been my experience that when someone has to say things like that, usually the exact opposite is true.
  10. haha yeah I have to say I'm very happy about that. And it's a 6-cell too! I'm fine the battery sticking out from the bottom the 1/2 inch or so but 9 or 12 cell would be too much IMO (as far as battery sticking out from bottom), but damn, if I get almost 5hrs out of a 6cell on balanced... I think I'm gonna try running it on "power saver" performance level this weekend. If I can live with performance loss from that, that will be all the much greater bonus. I don't use it for games or anything..
  11. I'm not sure what they base that number off of, but I have mine set on balanced and doing a normal work session, hopping from html-kit, multiple browsers/browser tabs, ftp program, various IMs running, popping in and out of excel or whatever, I get just shy of 5hrs.
  12. Yes, I read your response just fine. You say that lmgtfy.com is somewhat condescending. Well that's a negative word. Therefore you must feel some kind of offense. Otherwise, you wouldn't consider it condescending. That's like my wife saying "I'm not mad. I'm upset," when I say "why are you so mad?" That's playing word games. If you want to do that then fine. You were <insert negative word of your choice here>. You can't logically not insert something there and at the same time feel something is condescending. Doing so would turn the laws of the universe upside down, open up a blackhole and suck everything out of existence. My goal here was not to offend you or be rude. My goal was to point out that if you had been more specific in your OP, you wouldn't have gotten a response that you felt was condescending. I didn't say you were being too lazy to search for things, but that you come off as such when you don't post details of what you did do. My post was advice to you about making better posts and receiving better responses in general. TBH I really don't like arguing all that much. It's just that people like being wrong, or just plain stupid. Or stupidly assume things. If someone gets offended by me pointing that stuff out, then obviously the issue is that they cannot handle criticism. Even if I were to concede I was just plain flat out being a dick about something, that doesn't mean I'm pointing out something false. It just means that (in your opinion), I suck at delivering the message. Which is worse, the guy who sucks at delivering the message, or the guy who refuses to acknowledge a problem just because it wasn't pointed out in "the right way"?
  13. I just bought this laptop a couple months ago. Pretty decent for work, IMO. Can't say I care for the gloss finish though. I thought it would be cool but gd constant smudges all over the place are annoying.
  14. You attach the samophlange to the USB. Actually you need 2 samophlanges, since it's USB 2.0. Then hook the other end to php. You can also use it to I/0 R2D2 at the same time. You have to insert the samophlange into the back end for that though.
  15. hmmm...are you like, pulling the results from the db and storing them in an array and paginating based on the array (array being stored in a session or flatfile)? Because if you are calling that on every page load, there's no reason it should not be returning different orders every time. Post more code.
  16. did you try using a samophlange?
  17. Well you could always build your own standalone client in C++ or some other full flavored programming language...
  18. // example of the content... $string = <<<CONTENT MySpaceRes.Header = {"Cancel":"Cancel / Cancelación","Continue":"Continue / Continuar"}; MySpace.ClientContext = {"UserId":-1,"DisplayFriendId":10751728,"IsLoggedIn":false,"FunctionalContext":"UserViewProfile","UserType":1}; MySpace.StaticContentBase='http://x.myspacecdn.com'; MySpace.ClientMaintenanceConfigs = CONTENT; preg_match('~"DisplayFriendId"\d+),~i',$string,$match); echo $match[1];
  19. Post example of actual content you are trying to regex, including a line or 2 before and after the ID
  20. they are being removed from the core as of php6, though you can still manually install them as an extension.
  21. If you click the magnifying glass to the left of the input field, it will take you to an advanced search screen. In there, you can specify user.
  22. Instead of being somewhat offended, perhaps you should take a step back and work out why you were responded to in such manner in the first place. You did not mention in your OP what keywords you tried or what you found that wasn't great, so your OP pretty much came off as "hi, I need blahblah but I'm too lazy to search for something myself." So in your next post you mentioned that "oh hey, those are the right keywords! I had been trying with blahblah" well if you had mentioned that in your OP, you probably would not have gotten the response that you did.
  23. I'm afraid I don't understand this whole delimiter business. That doesn't look like anything mentioned in the OP. As far as I can tell, simply doing $string = wordwrap($string,90); should do the trick.
  24. create a login system.
×
×
  • 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.