« first day (989 days earlier)      last day (3962 days later) » 

12:00 AM
It seems like it was my own fault (and when is it not?). I had used an exit in my tearDown because I wanted to prevent cleanup of the database and forgotten to remove it. The execution of tests wasn't influenced because I am using @runTestInSeperateProcesses
Still, I would have liked something other than silent failure
 
Cracking passwords was never easier:
0
A: will triple hashing passes make them more secure php,

ircmaxellSo, to demonstrate why specifically this is a spectacularly bad idea (to put it lightly), let's examine the code that you have: $input_pass = 'example'; $step1 = md5($input_pass); Ok, so you generate an MD5, and then completely ignore it... $t1 = hash('sha512',$input_pass); Now you hash th...

 
@Jasper I think you're alone ...
 
@HamZa That just means I can vent without bothering anyone. (Unless you meant I am alone in wanting that, but I don't think you did.)
 
preg_split is not getting the entire word..
var_dump(preg_split("/[(a-zA-Z)]\/[(0-9)]/", "getById/25"));
returns this:
array(2) {
  [0]=>
   string(6) "getByI"
  [1]=>
  string(1) "5"
}
 
@Jasper I meant that nobody is responding to you ...
 
12:04 AM
@rogcg yes, that's correct
 
@ircmaxell master !
 
@ircmaxell why?
 
You're only asking for a single digit in the regex
 
Morning
 
what is wrong in my regex?
 
12:05 AM
@rogcg It matched d/2 and removed it from the output
 
how my regex should be?
that matches a 2 digit number?
it should be a regex
 
@rogcg , are you sure that you want to use preg_split?
 
I guess. what you suggest ?
 
@rogcg dumb question: why not explode('/', $string) and parse it?
 
You are using preg_split, what is matched is removed from the output. Are you sure you want to match the number?
@HamZa well, I was mostly just venting (though I wouldn't have minded someone offering insights) so it wasn't really a problem
 
12:08 AM
@ircmaxell OHHH how I didnt see that!!! sorry for that.
 
12:19 AM
@ircmaxell, i think that there is no conflict between forward compatibility and backward compatibility. :^ )
 
huh?
 
@ircmaxell , i can start with forward compatibitilty, but it does not take away my responsibility about old API. I think that i can use both approaches.
 
ok
 
"If your project aims to provide backwards compatibility as a primary goal, you're a sucker" --i totally agree
 
One thing I absolutely hate about programming is that you can't plan. I planned to successfully finish working on multiple features today and one small mistake has prevented me from finishing the first task. OH GOD WHY!
 
12:26 AM
 
@AshKetchum , call it 'feature' and go further...
 
You mean leave it in a non-working condition?
 
@AshKetchum , working and non-working are abstract concepts...
 
Its broken because its giving me stupid errors on connecting to the fricking database.
I am like 98% there and then I get Fatal error: Call to a member function prepare() on a non-object
I have like 2 minutes of stuff to do after it, but of course, the database doesn't want to cooperate.
 
12:31 AM
Hm... while I found @ircmaxell's article a really interesting read and agree with its main points, I would like to point out that forward compatibility is also used to mean something else: making sure older versions of your application can use input generated by newer versions gracefully. It is even more of a mess than backwards compatibility...
 
to an extent
 
Main point: when you would create a function add last param $options :^ )
 
For the one project I happen to know they strive for such forward compatibility it was a real mess. Their reasoning actually went: no we can't do that in our current save file format, and we can't change the format, as that would break forward compatibility. So they didn't even really consider implementing the feature.
 
Is there a simplified version of the explanation for why the following error occurs?
Fatal error: Call to a member function prepare() on a non-object pdo...
 
@AshKetchum , your variable is null.
 
12:39 AM
@sectus very much no
 
require ($_SERVER['DOCUMENT_ROOT'].'connect.php');

function check()
{
	try {
		$result = $db->prepare('...');
 
0
A: Modified PHP MD5 gives different hashes

DaveRandomAs I already outlined in a comment above, the root cause of the problems you are having is that PHP has no concept of unsigned integers, and it handles this by converting numbers that overflow the bounds of an integer to floating point (which doesn't play nice with bitwise operations). This means...

 
I literally have that same line in another fine and it works fine. Except in this file, it shows a problem :(
@sectus ^
 
Setting aside the ridiculous nature of what the guy is actually doing, it can be made to work
But that is a bad implementation of a very odd thing to do in the first place
 
@ircmaxell , ok, but you may continue your article with forward compatibility tools and ways.
@AshKetchum , turn on all errors.
 
12:42 AM
I must now?
last I checked I wasn't getting paid for these posts
 
Notice: Undefined variable: db @sectus
 
@ircmaxell , 'must' -> 'may' - fixed
 
but how is it undefined if it works fine in another file and I have exact same two lines in another file?!
 
It's good theme of research: forward compatibilities tricks...
@AshKetchum , show it with pastebin.com
 
eih
 
12:46 AM
cannot translate it : )
 
you're wrong and then you must (or may, whatever) continue your article..., great way to get me to want to keep going...
 
@ircmaxell , i didn't say that you are wrong. You are right... honestly...
 
31 mins ago, by sectus
@ircmaxell, i think that there is no conflict between forward compatibility and backward compatibility. :^ )
 
Can someone explain the value of..
$answer = $this->db->select("*")->from("table")->where("1=1");
over
$answer = $this->db->query("SELECT * FROM table where 1=1");
I don't get the point
 
Evening all :)
 
12:53 AM
@ircmaxell , it's my opinion about relation of this temrs. But i think that forward compatibility it good by itself, no matter what else.
 
See it?
?
@sectus ^
 
@AshKetchum , it's non-working one. And where is working?
 
@sectus Its the same lines except with a different SQL query and ../connection.php instead of connection.php
 
@AshKetchum , PHP has only two scopes of variable: local and global. Your $db variable in global scope, but you trying to use it from local scope. You must use global or use function param.
 
@sectus by "You must use global or use function param." do you mean declare $db as global in connection.php file?
 
1:03 AM
@AshKetchum , no, in function...
 
Wait, I am confused because if I understand right (which I am guessing not), then this is completely different than any other programming language.
You want me to put $db as global $db and then do the $result=$db... ?
 
function check()
{
	global $db;
	try {
		$result = $db->prepare("...");
@sectus like that?
 
@AshKetchum , something like this.
 
@sectus Are you showing an example or referring to what I wrote?
nvm
 
1:11 AM
@AshKetchum , working?
 
yes, incorrect reference to the connection.php file is ticking me off.
 
Blech
global $db; looks like awful code
 
FIXED
@cspray Do you have a better solution?
 
@AshKetchum Not use global state and inject your DB object/resource
 
Elaborate...
@cspray ^
 
1:21 AM
Well, since all I have seen so far is a procedural function...
function check($db) {
    // do stuff with $db
}
google dependency injection for more information
Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time. This can be used, for example, as a simple way to load plugins dynamically or to choose stubs or mock objects in test environments vs. real objects in production environments. This software design pattern injects the depended-on element (object or value, etc.) to the destination automatically by knowing the requirement of the destination. Another pattern, called dependency lookup, is a regular process and reverse ...
 
But then from whichever file I call the check function, I will have to make sure I have access to the $db variable too for the parameter.
@cspray ^
 
Then solve that architectural problem instead of just slapping global on your $db connection
 
Well that's a problem then because I am calling the function in the same file and it would be the same problem regardless of whether I put $db in parameters or in the method, since both ways would require access to the $db variable in that file.
@cspray .
 
Yet another book down:
0
A: Is "double hashing" a password less secure than just hashing it once?

ircmaxellI almost don't want to answer, because everyone with an answer here is right to some degree. But I also feel that everyone is also wrong to some degree as well. To those who say it's secure, they are correct in general. "Double" hashing (or the logical expansion of that, iterating a hash functio...

 
One moment
 
1:28 AM
 
What that guy smarter than me said
 
WHY the heck are you creating a custom MD5 function? This smells of you're doing it horribly wrong. I understand you may find yourself in a situation where this looks like the correct approach, but seriously, it's not. Ever. Fix the original function to use a more appropriate hashing algorithm (like SHA-2 or SHA-3), and migrate the existing hashes. But don't perpetuate the horrors here... — ircmaxell 49 secs ago
 
Sometimes I wonder what is tougher, life or programming?!
Can I just create a function in connection.php getDB() which returns the $db and then do something like check(getDB()); ?
@ircmaxell @cspray ?
 
Programming, like life, is as tough as you want to make it. Life, unlike Programming, is not really an optional direction (discounting the one escape)...
 
1 min ago, by Ash Ketchum
Can I just create a function in connection.php getDB() which returns the $db and then do something like check(getDB()); ?
 
1:43 AM
@AshKetchum This could be one way to do it. However I would be leery of getDB() functions in my own code or code I worked with. From an understandability standpoint it seems like you might be connecting to the DB more than one time. Although this might not be the case because of caching I'd still rather see check(PDO $pdo) or some other DB abstraction interface.
But I think your'e looking for a one-size-fits-all, golden hammer rule for dependency management that can be applied to your situation blindly. I don't believe it is that simple. Dependency management is a complex part of any application architecture and the best way to handle that is gonna vary based on your existing architecture, overall design of the system and what you want out of it in the end.
 
@cspray The problem that I have with the check(PDO $pdo) is that in that specific situation, I am calling the function in the same file, which would then mean that I have to get a reference of the pdo variable from the connection.php in some way.
 
If you're really just curious as to how I solve the dependency management problem I wrote an article on the subject for how I deal with dependency management in my personal framework. I don't tout this to be the best or only way and it certainly has its drawbacks. But it is testable and, so far, has been relatively simple to work with.
But outside of you just doing research on how to solve this problem from an architectural standpoint I really can't help you out much more than that. You could just slap global on your database connection. I'd advise against it though; you'll gain more out of fixing this architectural problem in the long run and save yourself a future headache
I would definitely check out how projects other than my own solve this problem. Then apply what you've learned to your own code
 
I guess I could create a separate file, include this function file and then in that separate file, but then I will have the same problem again: how do I reference the db variable without reconnecting there.
@cspray last thing. Should I dive into OOP and just create a new database object with methods I will need and then use them instead?
0
A: PHP: PDO global database variable?

Brandon SmithCreate a on object that holds a private PDO Object and define a public query method that accepts table name, column name, and value arguments and can be called repeatedly: class DatabaseObject{ private $db; public function __construct() { $this->createDB(); } private function creat...

Like that ^
 
2:01 AM
@AshKetchum I would personally get into OOP. Most PHP jobs you find these days require it
@AshKetchum In my opinion, no. And for one reason in my own code base. It would be nearly impossible to write a unit test for that piece of code.
If it isn't testable it isn't even anything I would consider using.
At least not willingly in my own personal projects
 
How is it not testable?
because the object is limited to one database connection?
 
@AshKetchum Not just one database connection but the very configuration of that database connection
I couldn't, for example, pass a mock PDO object that performs no database queries
But still validates that certain queries are called
Code with global state or hidden created dependencies is extremely hard to write a good unit test for
 
@cspray Well, I guess it has to be the public function insert(...) which breaks the quality
 
No, not really. It is the fact that the PDO object is created internally within the object itself. I can't control the creation of the dependency
The code itself controls it. I don't like that. I want to be in control of creating all the dependencies in my project
Your code tells me what I need to use it and I'll provide it
Even if you didn't want to expose the fact that it was a PDO wrapper. You could still have the configuration details passed in the constructor
 
Oh god. I am clueless and this whole project has come to a full stop once again with this issue.
 
2:10 AM
Also that particular code is horribly open to SQL injection and a host of other problems. Please do not use it.
Blech. The top voted answer and comments make me kinda sad that would come from such high reputation users.
 
@cspray How about this:
9
A: Set a PHP object global?

netcoderYes, you can make objects global just like any other variable: $pdo = new PDO('something'); function foo() { global $pdo; $pdo->prepare('...'); } You may also want to check out the Singleton pattern, which basically is a global, OO-style. That being said, I'd recommend you not to use gl...

Check what he put under "You should do that instead:"
 
@AshKetchum Yes
 
user652649
morning
 
@cspray I am kinda confused what makes that qualify instead of the previous one. What made you say Yes as soon as you looked at it. Must have been something that stood out?
@Wesツ hey
 
@AshKetchum The fact that the PDO object is injected directly into the constructor. This immediately tells me that I need a database connection to use your object. It also allows me to write unit tests for how this object interacts with the database because I can replace the object being injected to fit my needs.
 
2:19 AM
@cspray I am really not sure how I would integrate my situation with this code.
 
@AshKetchum This is the joys of programming ;) I like architectural challenges and figuring out how to solve them.
But like I said, there's a ton of different ways to do it and you gotta figure out what works best for you and your teammates
 
Also an epic waste of time, but as they say, you gotta do what you gotta do.
Its actually me alone, single-handedly developing it.
Also, isn't that code Object Oriented?
 
If you learn something valuable it is not a waste of time
Eh, yes, I believe that the last example is. But I don't think you can tell off one skeleton class whether or not a system is OOP
Just because it has classes and you create objects does not make it Object Oriented Programming
 
I am developing DB wrapper. What I must do when I am trying to fill numeric field with '000000000' value?
Swallow it like (int)0 or throw error 'is not a numric'. filter_var with FILTER_VALIDATE_INT does not consider that this value is numeric
 
Programming, like life, is as tough as you want to make it. Life, unlike Programming, is not (discounting the one escape) optional...
 
2:29 AM
Words of wisdom.
 
Or can i consider that '000000' is numeric?
 
@cspray Not trying to annoy you, but i'm still confused. I might need serious help on this.
 
Well, we're getting into deep water with that...
And I'm also not sure how much longer I will be up
 
@cspray Well, it would be great if you can help as long as you're up. I am not forcing you, but if you could help me get started, it will really help me.
 
I think you should do some googling and reading. I happen to enjoy Clean Code and recommend it. If you search around there's some other books that people recommend for various different things
 
2:39 AM
...ok :(
 
2:55 AM
Dammit, anyone else in this room besides cspray?
 
@AshKetchum , ?
 
@sectus I asked because I still couldn't solve that problem and I am trying to solve it now, not save it for later, but I think you busy with your own problem.
 
@AshKetchum , just ask it...
 
@sectus I have the PDO connection in one file called connection.php. Then in another file, I include that connection.php file and use the $db variable to run queries. Except to do that, I have to make $db global, which is an awful practice and enables dependency injection and all sorts security problems. Need to find a way that doesn't involve making it global
 
@AshKetchum , DI : )
 
3:03 AM
@sectus What?
 
ok... there is several patterns.
 
...ok...?
 
In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation. Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined. ...
 
@sectus so you want me to implement an object that deals with the database?
 
@AshKetchum , it's up to you.
 
3:10 AM
@AshKetchum hi, dependency injection isn't a bad thing?
 
@sectus I am confused, that is why I asked in the first place.
@Paul I didn't understand you. Are you asking me if it is a bad thing?
 
> which is an awful practice and enables dependency injection and all sorts security problems.
 
@AshKetchum , i cannot give you silver bullet. But there is a few bullets... choose one.
 
@AshKetchum Well, I don't think it is a bad thing, but you listed it as a bad thing and I was wondering why?
 
2 hours ago, by cspray
@AshKetchum Not use global state and inject your DB object/resource
 
3:15 AM
Which should be read: "Not use global state, instead inject your DB object/resource".
 
@Paul Whoops, but my main concern is having to use global $db to deal with this.
It has been told to me in such a way that using global is risky and creates security problems.
 
@AshKetchum Yes, so if you don't use global you have to pass in $db to the scope that needs it. Just like that answer you listed above.
 
Except how do I get pass the parameter when I am calling the function in the same file.
I must have access to the variable, right?
But how would I use it without it being global in the first place?
 
@AshKetchum , why you are not using OOP?
 
You mean something like this?
class TableCreator {
   protected $pdo;

   public function __construct(PDO $pdo) {
       $this->pdo = $pdo;
   }

   public function createFromId($id) {
       $stmt = $this->pdo->prepare('SELECT * FROM mytable WHERE id = ?');
       $stmt->execute(array($id));
       $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
       foreach ($rows as $row) {
           // do stuff
       }
   }
}
 
3:20 AM
It's okay if it is global to begin with, but all of your classes aren't aware of the global state, they use what they are passed.
 
@sectus @Paul ^
 
@AshKetchum , yes...
 
@sectus but with that method, I would literally be going around in every file and instantiating a new database object (PDODatabase $db = new PDODatabase)
@Paul but then half the website would be relying on what is passed and the other half would be relying on the global variable.
 
Actually, you would instantiate $db at the global scope (your main method) and pass it to all that needs it.
$tableCreator = new TableCreator($db);
 
and where would I place that line ^?
in connection.php file?
 
3:24 AM
$tableCreator = new TableCreator($this->getMock('PDO')); // When you are unit testing.
 
@Paul I would place that in connection.php file?
?
 
I like the link that sectus gave you about Creational Patterns. Where you create your objects is up to you. It depends on what you are going to do.
 
@Paul I will give you my situation in 2 sentences and then please respond to what you think about it.
 
ok, yes
 
<?php
try {
	$db = new PDO('mysql:host=...;dbname=...', '...', '...');
	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}catch(PDOException $ex)
{}
?>
That is my connection.php file.
function check()
{
	global $db;
	try {
		$result = $db->prepare("...");
That is my test.php file.
Now, as you can see, $db is declared in connection.php file but I make use of it in different files throughout the site.
Should I change that whole connection.php scenario to OOP and program it as an object?
@Paul ^ Please read and respond.
Something like the following:
11 mins ago, by Ash Ketchum
class TableCreator {
   protected $pdo;

   public function __construct(PDO $pdo) {
       $this->pdo = $pdo;
   }

   public function createFromId($id) {
       $stmt = $this->pdo->prepare('SELECT * FROM mytable WHERE id = ?');
       $stmt->execute(array($id));
       $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
       foreach ($rows as $row) {
           // do stuff
       }
   }
}
?
 
3:33 AM
yes, I think the connection either belongs at the global scope or it should be created using a creational pattern such as a factory.
 
@Paul But then, how do I reference the object in the test.php file?
 
You can't really have pure OO everywhere, at the start of your program objects need to be created. But once they are created they can be passed to every other object in the system.
@AshKetchum test.php isn't an object? If it was you could just call new Test($db)
 
@Paul But how do you access $db in the test.php file?
 
@AshKetchum Why is test procedural? If you want to pass an object to a function: function check($db)
or, even better, typehint it too: function check(PDO $db)
 
@Paul What I am asking is how do you get access to $db? Even if I have function check($db) and then I call that function, what would I put in the parameters when calling the function?
Also, would it be possible for you to reply a little quicker, since I am here for just a few minutes before I have to leave and I am really trying to get this working before I leave.
 
3:41 AM
@AshKetchum Pass it from the top. You create it at the global scope. You need to create all of your objects first, and then pass them to whatever depends on them.
 
is making it global safe?
The only object I will have is the database object in connection.php file
@Paul ^
 
Yes, you have to have something at the global level. I think i'll have to leave it with you.
Those are my thoughts, you'll have to work out what makes sense for you.
 
@Paul if making it global is ok, then why did @cspray say that isn't a good solution?
 
Dependency Injection, Inversion of control.
@AshKetchum There is a difference between the global scope and using global.
There has to be one scope that rules them all, it is the start of your program. But leaving every other part of your system dependent upon that level for storing and retrieving state is a bad idea.
But objects can manage their own state and hide it from the global state which is good.
 
Can I do the following:
add dependency - function check(PDO $con)
then when calling the function, just do check($db) and put include('connection.php'); on the top?
@Paul would that work?
 
3:49 AM
yes, that looks good.
 
@Paul It works! :) Thank You.
 
Your dependency is now injected, so your check function doesn't depend on the global state anymore. You could actually pass it a mock object later when you want to test it (rather than it being hardcoded to global $db).
 
For some reason, I was thinking that dependency injection is bad or some security hole.
I guess I was relating it to MySQL Injection :D
 
No worries, i'm glad it works for you.
 
Thank you. :)
 
0000 is not an integer value.
 
4:40 AM
@sectus The OP was looking for descending order. :)
 
5:14 AM
anyone here
 
Yeah wassup
 
Hey guys
 
@ircmaxell you really should fit all your books on SO together in a real book…
 
beep
 
5:32 AM
hello
Can we know, current date falls under which week of month in MySQL.
-------------------------------------------------------------------------

Today : 2013-06-01 [ Falls on first week of Month ]
Random : 2013-06-17 [ Falls on third week of Month ]
 
@Wesツ i need in mySQL
 
thanks
 
5:51 AM
Is there anyone here who has PHP experience and wouldnt mind answering a question?
 
go head.
@Tredged Discussion for all things PHP - Don't ask whether someone is here to help you. If someone is around and wants to help they will.
 
Is it possible that if a script is executed and a output from the database is generated to send all users online on the website a alert?
Thanks once again ;)
with that output*
 
you want to send a notification or email
 
Notification
 
ajax push notification @Tredged
 
5:54 AM
yes you can
with email and notification
 
Hi, anyone here available for magento question?
Can I export product by id range or date range? Thanks
 
Yogesh or Rafee you got any example or link for me to see?
 
@Tredged , variants: update page(iframe) every couple of seconds, send ajax request, use comet or use websockets.
 
@JeffreyCarandang Can you get the result set of what you need.. then you can do it.
 
Thanks!
 
5:57 AM
@Rafee Hmm, how can I do that. Is there advance profile for that?
 
Does stackoverflow have a marketplace or you guys know any I need someone who can fix some jQuery issue which for me is impossible
 

« first day (989 days earlier)      last day (3962 days later) »