Jump to content

iansane

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

iansane's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all, I'd like to bring this topic back up since it's 2011 and I still have the problem of finding real world examples. I have looked with google and I have tons of php ebooks that barely mention this part of OOP. Daniel10's example is much better than the whole dog/cat or car/van and definitely much better than the foo/bar examples. Daniel10's example is real world and can be explained in the same way as the dog/cat examples but it's easier to understand in my opinion. I think it would be great for all beginners in the PHP community if we accept that there are tons of dog/cat/car/van/foo/bar examples so understanding the concept at a beginner level is not in question any more. Now truly understanding the concept by seeing how it works in a real world example is what is needed. For example, I tried to understand extending exceptions at php.net http://php.net/manual/en/language.exceptions.extending.php (example 2). I started asking around on forums and was being advised by many people to make an abstract class because it apparently is bad practice to directly extend a core class. I never did find out why this is bad. But anyway, when I asked about how to do this I kept getting the foo/bar and cat/dog responses which made no sense to me at all in the context of creating an abstract class to extend exception and then how to use that class in a real program. It's silly that some people seemed to go so far out of the way to make sure they didn't write the code for me that their examples were just ridiculous. I don't want someone to write an application for me. But for a few real world examples it would be nice to see complete code and an explanation of it. That's the kind of example I would love to see with a explanation of why and how it works. Would anyone like to share abstract classes they use in their own applications and a brief tutorial of the why's and how's? I hope you don't actually have a program for tracking cat/dog inventory or monkey's, giraffes, and tigers at your imaginary zoo. :-) Thank you to anyone who wants share your knowledge and skill so beginners can learn something real.
  2. Thanks you guys. All the examples and explainations helped me understand arrays and php much better. I tried all the different ways and they all worked. Was able to move on in the book. Thanks for the help. I'll mark solved
  3. That just displays the word "Array". I tried print_r() and it worked. It actually sorted the array. If I wanted to still have a copy of the unsorted array, (I don't know if there's a good reason), I'm guessing I have to make a copy with another name and then sort just one of them? Is there some kind of copy_array() function? I know in c++ I would use a for loop and increment through each element writing it to another array. Is that what needs to be done in php? Thanks
  4. Hi, I am fairly new to php. I'm learning from "Beginning PHP5" (2004). I'm having trouble with the sort() and asort() functions on arrays. They don't seem to be working right. Here's the code: <?php $my_unsorted_array = array("jim", "bob", "mary"); $my_sorted_array = sort($my_unsorted_array); //according to the book this is all there is to it //now trying to display the sorted array just displays a "1" and nothing else print_r($my_sorted_array); //displays a "1" echo $my_sorted_array; //displays a "1" echo $my_sorted_array[1]; //displays nothing and no error message I have the same problem with asort() Is this the correct way to use sort() if I want to have both a sorted and unsorted array available to work with? BTW print_r() works fine with the first unsorted array. Thanks
  5. my mistake. It should be settype($my_var, "string"); time ran out before I could edit the last post
  6. OK, I figured this one out. After looking at it again I thought line 3 doesn't look right. It should be settype = ($my_var, "string") NOT as the book says, $my_var = settype ($my_var, "string") I still don't know why this caused it to change the type to boolean. I guess I'll need to spend more time modifying code to figure it out when I have little problems like this. I don't know if the book was trying to make a point or just had a typo. Who would expect the code in a published book to be correct or for there to be complete explanations in a book titled "Beginning PHP5"? (sarcasm) :-)
  7. Hi, I'm just starting out and learning about settyp() and gettyp(). I used the following code and the resulting data type is wrong. $my_var = 1995; //$my-var is a numeric value echo "The varaivle is now a ". gettype($my_var) . "<br>"; $my_var = settype($my_var, "string"); //$my_var is now a string echo "The variable is now a " . gettype($my_var); the result is that the variable is now "boolean" and the data contained in it from "echo $myvar" is just "1". In the book it says something about "not the string you were hoping for" but I don't see any explaination of why and how to resolve the problem. Can someone please explain this to me? Sorry to have to post such a small thing but it's hard to learn when right off the bat things aren't working right. Thanks
×
×
  • 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.