logs archiveIRC Archive / Freenode / #php / 2015 / July / 20 / 1
SlashLife
What's a "static class"?
lucyfx
something that doesnt exist in php :p
SlashLife
Good. Good, good.
(Action) goes back to sleep.
Literphor
strmfy: If you store an instance in a class in a private property thats not static&this isnt a singleton, this isnt the issue. If you store an instance in a class and its a static property then the problem arises because youre relying on static/global state and thats the real issue with singletons
lucyfx
thats the point of having a singleton...
Literphor
strmfy: and unless youre going through great pains to restrict access to that instance then youre opening yourself up to issues where that global/static is changed by something, somewhere when it hsouldnt be. You dont know where, you dont know why, you dont know and have fun figuring it out
Happy_the_Exceed
lucyfx, singleton is mainly to restrict to only 1 instance.
sorabji
lucyfx: do you know what coupling means?
theskillwithin
i feel like I wont ever really understand namepsacing because it is only used in huge programs
         

sorabji
theskillwithin: nonsense
strmfy
Literphor exactly, but if the instace stored as a static has private vars they cant be altered in that way. Or am i missing something?
theskillwithin until you start using frameworks ;)
lucyfx
isnt namespaces pretty common these days, like in... everything?
ExoUNX
Literphor, ok nvm, the login script is not working
Literphor, and it's not spitting any errors to me
Happy_the_Exceed
lucyfx, Given the nature of code (Modular code with changing parts http://toolguyd.com/blog/wp-content/uploads/2013/10/Kobalt-Stubby-Double-Drive-Screwdriver.jpg - testing code with changing parts to ensure quality ) - You then find that Singletons are bad for most things (almost everything)
strmfy
lucyfx yes,pretty much
__adrian
lucyfx | thats the point of having a singleton... // YES. it _is_ the point. it is also the flaw. this is why singletons are bad.
Literphor
strmfy: Ok so you have a static instance saved as a private property but you have some kind of public API that makes modifications to that instance& but that function is going to be public and since its also static that means anything from anywhere within your system can call that function and make changes to your instance when you didnt want it too
strmfy: This especially becomes an issue outside of PHP when you do concurrent and asynchronous programming
ExoUNX
Literphor, the redirect page after login basically checks for $_SESSION, not found redirect to index or stay on index. If it doesn't stay on the page
theskillwithin
I don't think ill be using frameworks any time soon
I do smaller stuff with PHP
As usually I read about it in an outdated book and then walk away not really understanding the practical applications
Happy_the_Exceed
This is the part where singletons go bad. Testing with changing components.
strmfy
Literphor yea I get your point. I prefer ignoring the implications though ;)
sorabji
theskillwithin: just read the manual. it explains namespaces just fine
lucyfx
Happy_the_Exceed, almost everything is not a good reason to avoid something for ->everything<-, the discussion here is not making all the classes in existence singular
singleton* whatever
theskillwithin
hmm
ExoUNX
Literphor, this is the line - if(empty($_SESSION['user']))
theskillwithin
so If I have two classes with the same name id use a namespace to differentiate them?
Literphor
strmfy: By the end of the day, the problems singletone fixes arent really problems at all&it just takes a slightly different mindset where you make your instance availble when its needed rather than always making it available.
theskillwithin
seriously sounds like osmething id never have to do
lucyfx
ExoUNX, are you checking that value after settings session, during the same runtime?
setting*
         

sorabji
theskillwithin: that's one use among many
ExoUNX
lucyfx, I also want to mention that the login is successful otherwise it would print that it wasn't
lucyfx
so session['user'] works, it has a value etc?
strmfy
Literphor I guess when it comes to async programming you can overcome most of the obstacles with mutexes as well
ExoUNX
lucyfx, lol it actually doesn't print it
theskillwithin
some advice, amazon prime is like crack, do not get it you will not have any money left over after the trial
lucyfx
maybe it worked once and your browser now server the header from its cache? please avoid header for testing
there is a session_start etc. at top, right?
Literphor
ExoUNX: Then $_SESSIN[user] is empty, maybe after a successful loging you need to set it to something, like its userID?
lucyfx
can you post the register and login page?
Literphor
ExoUNX: I dont know but if the login script is old and you dont udnerstand how it works, maybe you should roll out your own?
ExoUNX
lucyfx, Literphor, here are the scripts - http://hastebin.com/raw/exiritiqey
lucyfx
require("config.php"); can you post this too?
<?php
require("config.php");
if(empty($_SESSION['user']))
there is no session_start here
ExoUNX
lucyfx, yes, come of it
lucyfx, some of it*
strmfy
Literphor But lets say that the private static object only loads a specific config file (using some naming convention) and inits a logger using a path specified in that config no public SET methods are required. Isnt that the prime usage of a singleton?
lucyfx
are you calling session_start, anywhere?
there is no session_start in your code
Literphor
strmfy: Mutexes help, but then you open youself up to the issue of locking resources when they need to be available.
ExoUNX
lucyfx, http://hastebin.com/rixosamuwa.php
SlashLife
ExoUNX: Any particular reason why you don't use password_hash?
lucyfx
ExoUNX, also you dont need to keep salt in database, or do it like this. writing this using password_hash / password_verify will be better and shorter for what it matters
Happy_the_Exceed
Hello there ExoUNX.
lucyfx
register.php doesnt load config.php, so it has no session start
same goes for login.php
so you arent writing the session variables
Happy_the_Exceed
lucyfx, if password_hash is used. The salt will be stored with the hash.
ExoUNX
SlashLife, I will be switching over to password_hash soon
Happy_the_Exceed, greetings
Happy_the_Exceed
ExoUNX, !+later
php-bot
ExoUNX, best practices  like input validation, prepared statements, testing, coding style, and so forth  are important. Many people say they "just want to get it to work" and claim they will "fix it later." Though they might even be sincere, it **never** happens. Don't be that person! Do it right the first time!
strmfy
Literphor True that
SlashLife
(Action) raises an eyebrow.
"soon"?
lucyfx
Happy_the_Exceed, I was talking about the "salt" field in his database
Happy_the_Exceed
Ah ah.
Mkies!!
__adrian
Happy_the_Exceed it's ok... i literally just told him about password_hash twenty minutes ago.
:p
Literphor
strmfy: No, the primary usage of singletons is to make a single instance available statically so its avaiable everywehre the class is. In your example you can just give it an object to do work, then once it done with the work you can get rid of it since you no longer need it
ExoUNX
also @the bot, yes I actually do fix the code lol
Happy_the_Exceed
Wow, at least he's on PDO.
ExoUNX, we're talking about NOW.
Like... Right now.
__adrian
ExoUNX, it's preemptive advice. most people don't. :p
Happy_the_Exceed
Really now.
Now now now. :)
ExoUNX
Happy_the_Exceed, ok fine lol, I'll do it and I'll report back with the script :P
Happy_the_Exceed
ExoUNX, dont come back without it.
__adrian
and even if they _do_ do it later, they've wasted time doing something else first.
ExoUNX
Happy_the_Exceed, promise, if I come back it may be fore help lol
Happy_the_Exceed
Or I will crawl through your computer monitor with a crazed expression on my face.
and it is not pretty.
ExoUNX
and thanks lucyfx for finding that
Happy_the_Exceed
ExoUNX, now you have to.
You made that promise.
lucyfx
see ya i guess :D
Happy_the_Exceed
GO GO GO GO!
lucyfx
is it fixed now?
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 next »