Jump to content
bigjoe11a

Uploading Files

Recommended Posts

Ok, The videos I been watching tell me the same thing, So how come I can't access the private variables from my class.

Share this post


Link to post
Share on other sites

You should be able to, which lines are you referring to where you try to access them and why do you think you actually can't access them as opposed to them just being empty? If you turn on maximum error reporting like I showed above then you will get an error message (a notice) if you try to access a variable that doesn't exist. If you don't see that notice, then you are in fact able to access it.

Share this post


Link to post
Share on other sites

Your going to have to go back and read from the top. I explain all of that in this topic. The idea is to access a private variable in a class. And i don't know why. Just refresh others memory. private $_imageName; //In my constructor. $this->_imageName = $_FILES['image']['name'] The above returns an empty value. How every when I did it this way. It worked.

class Profile { private $_imageName;public $imageName; //In my constructor $this->$imageName = $_FILES['image']['name'];$this->$_imageName = $this->imageName; // This works.}

Edited by Bigjoe

Share this post


Link to post
Share on other sites

Whether a property is public, private, or protected literally makes no difference inside the class. Public, private, and protected properties can all be accessed inside the class, always. They only matter from outside of the class (or in inherited classes). What you're describing, how you don't think it works to set it directly to a private variable, but for some reason it works if you set it to a public variable then a private variable, is not possible. PHP doesn't work that way. There isn't any bug like that, and PHP isn't going to treat your class any differently than it treats every other class. It sounds like you're trying to access a private variable from a place you're not supposed to, not that the private variable doesn't get set for some unexplainable reason. Have you added the code to set the error reporting options? If you're trying to solve a problem without bothering to check for error messages then you might as well be guessing.

Share this post


Link to post
Share on other sites
Your going to have to go back and read from the top. I explain all of that in this topic. The idea is to access a private variable in a class. And i don't know why. Just refresh others memory. private $_imageName; //In my constructor. $this->_imageName = $_FILES['image']['name'] The above returns an empty value. How every when I did it this way. It worked.
class Profile { private $_imageName;public $imageName; //In my constructor $this->$imageName = $_FILES['image']['name'];$this->$_imageName = $this->imageName; // This works.}

apparently you haven't been following anyone's advice, or you are not showing us the specific parts that they are asking for. what you are failing to provide is the entire context. Either you are trying to access them outside the class, or you are doing something wrong inside the class. Just showing snippets and misc. comments in this case is not doing anyone any good, and completely ignoring JSG's suggestion to add error reporting is just downright baffling. Wouldn't you at all be interested in knowing if there are errors? You might actually find the answer to your problem so much more faster.... given your lastest code example, not really sure how all your classes tie into together, since the whole thing hasn't been shown in one post, which would include the entire file exactly as you see it, and mention if files are being included or not. What has been constantly asked for is WHERE you are making the calls to access these members. A comment next to a line saying this works, this doesn't, is pointless, because how you are CALLING that member is why it isn't working, and that's what you AREN'T showing us. Edited by thescientist

Share this post


Link to post
Share on other sites

Look, thescientist Your going to have to do some back reading threw this topic ok. I'm getting tired of explaining every thing 2, 4 or 10 times. Ok. I told you guys that it does work. I have to set it to a public variable from a private variable. and I don't know why. I shouldn't have to do it like this. If I set a private variable to access any thing. It should return that value. and I have no idea why it didn't work this time. I use more then one class in this project and I never had this problem before. Then again I never used a class to upload a file. Any way here's where I get the video from http://www.youtube.com/user/phpclass and this good is good to. It gives details on what and how he does things and I never had a problem before. So I don't know what the class is doing what it is doing. I'll have to play a round with some more samples when I get some time.

Share this post


Link to post
Share on other sites
I'm getting tired of explaining every thing 2, 4 or 10 times.
You know, we're not stupid people. If people aren't understanding what the problem is, then you're probably not explaining it very well. The situation which you described, which you think is happening, isn't possible, so the answer lies somewhere in code that we haven't seen yet. You're seeing symptoms and assuming you know what the problem is, but what you assume isn't correct. Are you just not interested in having PHP tell you exactly what the problem is?

Share this post


Link to post
Share on other sites

Well since I do have error reporting turned on and if there was an error. PHP would tell me RIGHT?. well I never did get any errors. Like I said the values were all empty and I still don't know why. and a again. I never had this problem before. If you set a variable to hold a value. You should be able to use that value any where in your PHP scripts. In a class. private variables can only be used in that class. and That I do under stand. How ever I don't know why this didn't work the 1st time I set it up. Then again I never used a class to update a lot of information or even upload a file before. So this is all new to me.

Share this post


Link to post
Share on other sites
Well since I do have error reporting turned on and if there was an error. PHP would tell me RIGHT?
It depends on the PHP settings. That's why I gave you the code to turn on maximum error reporting and to make sure error messages are being displayed. Your PHP installation might only be reporting fatal errors, or warnings, but it is notices that you want to look for. If you want more help with this issue, you'll need to post the complete code for the entire class, and the complete code where you use it. Bits and pieces of the code aren't going to do it.

Share this post


Link to post
Share on other sites

Thanks. I did add the error checking like you said. and I have been able to fix some other errors I fount. and you will find the full code for the class on page one of this topic. I did want to tell you that I started setting up the blog part, and I added an option to upload an image. and well it makes no since at all. It works here. I didn't have to use public varibles in this new class I made for added blogs. So I have no idea why I have to use both private and public variables in the profiles class.

Share this post


Link to post
Share on other sites

You do not have to do that. That's what I'm trying to tell you. All classes follow the same rules. The problem is the way you are trying to use it is not correct, not that PHP is treating this one class differently than it treats everything else. I haven't seen enough code to tell you what you're doing that's not correct.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...