Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access private methods from outside a class

Tags:

visibility

php

I have a Bcrypt.class which contains my hashing methods and I have a userDAO.class which contains my register method.

In my Bcrypt.class the methods are private. How can I access them in my userDAO.class so I can hash my password?

Please let me know if you need to see any code.

like image 505
Cheese Puffs Avatar asked Feb 15 '26 17:02

Cheese Puffs


1 Answers

You cannot access private methods from outside of the class declaring them. If API developer decided to use private then there is no chance. I personally prefer protected in almost every situation. Some API developers don't..

If you have personal access to the source code of the Bcrypt class and you can change it without breaking anything then make the methods either protected and extend the class or make them even public

Another design approach would be to place the algorihms in a separate class and use them in the Bcrypt class and others

like image 83
hek2mgl Avatar answered Feb 18 '26 07:02

hek2mgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!