« first day (1009 days earlier)      last day (3954 days later) » 

12:03 AM
@PeeHaa I added the json_encode() to the return, and the single quotes like it console.log('<?php echo $managePress->ListDirsAndFiles(); ?>'); but it doesn't work
@PeeHaa It works, i forgetted to delete the quotes, sorry
 
@PeeHaa worked thanks!
 
@crypticツ looks good :)
 
Good evening. I am not even slightly very very drunk, and everything I say makes complete sense
3
 
@Ocramius now just need to figure out this auto-delete bug. I'm sure I got a logic problem somewhere. It's just SO has so many rules on what is and is not a specific type of question
@DaveRandom evening
 
@crypticツ hah, that will be flustercluck of code.
 
12:17 AM
It should also be noted that it didn't take me two minutes to spell check that previous message
Or that one
 
@DaveRandom you make ALWAYS perfect sense :P
@DaveRandom how about pair-programming on some jQuery plugin?
/me runs
 
In my current state of mind that would be fine, because the code quality I would produce would be on a similar level
 
@Ocramius yeah the other question types were easy to check, but there are literally four possible reasons to mark a question autodelete and each reason has a ton of requirements =o\
 
@crypticツ If you poke @Shog9 hard enough he might add a delete_at key (or whatever) to the API so you can just inspect that
 
I think there are no auto-delete questions that will show up in the backlog except for the delete after 9 days ones, because those are handled weekly. The other types might be handled on a daily cron so once they meet the requirements they have a small window to be marked as auto-delete before they get removed.
 
12:29 AM
@crypticツ is the source of this stackoverflow thing not available somewhere?
 
user895378
@bwoebi I'm not sure what to tell you. I can do 1,000,000 requests with 1,000 clients connected at once with apache bench and not get a failure if I run both on my local machine. I've been hosting the tests from my residential internet connection behind a consumer-grade router. It shouldn't be that surprising as it's not really high-end server-grade network infrastructure.
 
@Ocramius huh?
 
@crypticツ I'm wondering where these rules are written, and by whom ;)
s/written/implemented
 
SO code is proprietary as far as I know
 
The logic description is available on meta.SO, the sauce is a closely guarded secret
 
12:33 AM
@DaveRandom meh
I wanted to build a site called stack-sex-change, but I heard there's already one
 
However if you beat Shog9 up a bit he tells you stuff. And @balpha is also congenitally helpful.
heh, I said genital
 
isn't SO written in C#?
 
It's .NET
So probably c#
There may be some insane people who use VB
 
@DaveRandom if it just was cross platform sigh
 
especially based on the fact that some of the SE development was done by Fog Creek/employees/previous employees of Fog Creek
Maybe it's all written in wasabi. who knows
 
12:50 AM
hey, if I want to pass a JS var on that: console.log(<?php echo $managePress->ListDirsAndFiles(); ?>); how I have to do it?
the JS var into a ListDirsAndFiles() param
 
try console.log(<?php echo json_encode($managePress->ListDirsAndFiles()); ?>);
should work for arrays/strings/numbers, else you should be more specific
 
@DaveRandom I assigned a JS bug and enhancement to you, since you're the JS expert.
 
1:07 AM
RT @raganwald: Immuteability: The property of functional programmers that prevents them from shutting up about pure functional programming.
 
@FabrícioMatté hum, what I want it's to pass a param to the function. In other words console.log(<?php echo $managePress->ListDirsAndFiles(param1,param2); ?>); where params are a JS vars
 
1:25 AM
@acasanovas that's fundamentally impossible, see this for reference stackoverflow.com/q/13840429/1331430
gtg, have a good reading
 
MGE
2:13 AM
Hello, Im using try {} catch(...) {}
and Im trying to use new throw exception()
but I receive: Fatal error: Uncaught exception 'Exception' with message 'We have a problem in here' in /var/www
do you know why?
 
post the code
 
MGE
public function __construct() {
	try {
		pdo connection code
	}
	catch( PDOException $Exception ) {
    	error_log( $Exception->getMessage( ) . $Exception->getCode( ) . ' :: URL: '.     Controller::getCurrentPage(),0 ); //it works
     	throw new Exception('We have a problem in here'); //it shows FATAL ERROR
	}
}
 
2:28 AM
> When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception ..." message, unless a handler has been defined with set_exception_handler().
You're throwing an exception but not catching it so it will Fatal Error
Read up on Exceptions here php.net/manual/en/language.exceptions.php
@MGE I think what you are looking for instead of throw new Exception('We have a problem in here'); is trigger_error('We have a problem in here');
 
When is the need to serialize an object ??
 
before you save it
 
Hi, I am trying to put some info into a database using PDO and a foreach() loop in PHP. i am accessing the info from an XML file. here is my code.
$url = 'https://gdata.youtube.com/feeds/api/users/demoScript/uploads';
$xml = simplexml_load_file($url);
$query = "INSERT INTO videos VALUES ";
foreach($xml->entry as $entry){
$title = $entry->title;
$id = $entry->id;
$date = $entry->published;
$views = $entry->yt['viewCount'];
$rating = $entry->gd['average'];
$faves = $entry->yt['favoriteCount'];
$desc = $entry->content;
$values[] ="('".$id."','".$title."','*','*','*','*','*')";
}
$query = $query.implode(",", $values);
echo $query;
$db->prepare($query);
Obviously, I created my PDO object in the $db variable
The *'s will be replaced
 
3:02 AM
@MGE I really don't know anything about JSON. How would I have to change my code?
 
MGE
 $url="https://gdata.youtube.com/feeds/api/users/demoScript/uploads?v=2&alt=json";
 $json = file_get_contents($url);
 $data = json_decode($json, TRUE);
 print_r($data);
you will take the json info in your new array
 
3:27 AM
hello
 
hows it going
 
good, and you?
 
not to shabby
 
3:49 AM
Hello everyone.
I have a question about a quiz that I am processing. I have the quiz producing a percentage, and want to lock use of that quiz page for a specific time. I have been looking around, and haven't found anything relative to this. Help?
Like: Pass: get pass page. Fail: lock access to this quiz for 72 hours.
 
4:07 AM
@john for a specific user or for anyone?
 
4:17 AM
for a specific user. Although, I have that already ready. I'm going to have a value change when the timer is set, and when it runs out. I just want to figure out how to utilize the countdown, with it being so long.
Basically, I just want to figure out how to make it run in the background so that they can leave the page, and wait while they are still browsing around.
 
@John IP address
 
If security is not paramount you can just set a cookie that will expire in 72 hours and check that before showing the quiz again.
 
@Doorknob IP address?? As in utilize this by IP address? Would you mind sharing a link if you have one?
 
@John a link to what?
 
@Doorknob on how to utilize IP address with this method?? Or am I misunderstanding...
 
4:24 AM
$_SERVER['REMOTE_ADDR']?
 
@Orangepill security isn't a big deal at the moment, but may become a problem down the road. And would a cookie keep running even if they close the browser or shut down?
 
@John yes
 
Thanks @Doorknob I'll look into using that. I've done some research on $_SERVER['REMOTE_ADDR'] and found out that it isn't always the same...?
@Orangepill and if I have a cookie change a value in the database, it would run in the background, and then change the value again after it is finished running??
Or is that possible??
 
@John no, you would save the time that the user inputted a wrong password in the cookie, and check to see if 72 hours have passed since that time.
 
and if so, it would then change the value.
what if they move to a different device?
 
4:29 AM
yes
 
would they still be locked?
 
then... you can't do anything about that
no
 
well, if the value changed in the database when the timer was set, and then they move to another computer without running the website again on the computer they used previously, would the value stay changed?
 
um... what?
 
Computer 1 (main computer): they were locked by cookie, and cookie is running, and user lock value has changed from 0 to 1.
Computer 2: Still locked, because they haven't allowed the cookie on Computer 1 to fix the value from 1 to 0 to allow access.
Is that a little more clear? Or am I still misunderstanding?
So would that be the case in this situation?
 
4:44 AM
cookies don't transfer from one client to another ...
are you authenticating the user a logging them into your system?
 
Yeah, that's what I'm getting. Just trying to understand.
@Orangepill I'm letting users login with a session. They have page access codes to their ids. Those access codes have a lock value that will change from either 0 to 1 whether they are locked from that access code or not. I'm allowing a test/quiz for my media that I'm giving out, and I would like to keep them from taking the quiz twice over 72 hours. That's it.
access codes *connected to their ids. *
 
Sup?
 
you will have to add another table to your database that contains access_code, quiz_id, and lockout time.
before you show a quiz to anyone check that table to see if there is a record for the current user's access_code for the requested quiz that has a lockout time >current_timestamp. if there is then they are locked out until the lockout time (which would be a datetime field). If not then show the quiz.
if they fail a quiz then add the record to the database,setting the lockout time to 72 hours in the future
@ashKetchum nothing you?
 
@Orangepill haha nothing much here too
 
5:02 AM
@Orangepill Thanks. I'll give that a try.
 
 
2 hours later…
6:33 AM
any one here?
 
wassup?
 
@Orangepill do you know how to validate data in a MVC
application
well i know it should be done in the model layer
 
correct..
 
but I have this contact form with some basic fields.
and none of it gets stored in the database but would you call that form part of my model layer
so would i still follow the normal approach and extract the data from the request in the controller and then send the data to the model layer for validation
 
yes... it is a domain object so there should be some sort of form model
 
6:37 AM
specifically to a service so i can then send the email at the end
the contact form is a domain object?
 
yes... I would say so. It's part of the business logic
 
oh yeah true i suppose
could you think of it like if you had a shop in real life and had contacts forms
that would be part of your business model i suppose
another question. do you think it makes sense for this new domain object to have an ID? i am thinking no
just the fields in the form
 
the only difference is how you are persisting the data... for a contact form it is being persisted via a call to a smtp server.
just the fields... you won't be able to retrieve it but I think it should go through all the same motions as a normal model object.
 
makes sense
it might be going too far to run some sort of $storage->save($contactForm)
which actually sends the email
it disguises it too much it looks like it is going to the database
 
Another approach you might take is make it a method on appropriate existing domain object... say a SiteVisitor object.
 
6:46 AM
oh yeah
for Guest
because when they are logged in there is a better featured ticket system
 
Guest::sendContact($contactInfo) // can throw InvalidContactInfoException
Catch the InvalidContactInfoException and use that to use for feedback to the end user.
 
ok thanks
 
7:17 AM
good mornings.
Pro tip: Use _ instead of :: to learn more about the design of your PHP software and how to improve it easily.
 
what do you mean
 
If you have much usage of :: in your software you most often can easily improve it.
First of all you convert those :: into _'s so that it's clear that all these are global functions.
 
I will agree with that.... the above notation was to indicate a method on Guest... not a static one.
 
are you on about calling static methods? or using to it to call parent::someMethod()
 
7:23 AM
Then you can decide by the names / prefixes where you want - and if at all - you want to introduce objects instead.
@David static methods (global functions)
 
I have managed to create my application with no static methods so far
which is great
Never needed to use any
do any of you do unit testing
 
not yet
 
yes I do. you perhaps do as well if you've got no statics?
 
yeah I do and I have a question
I am not an expert I am still learning it
its another whole topic
I am testing my Request class
which is just a wrapper around some super globals
like $_POST, some $_SERVER properties like REMOTE_ADDR
it takes nothing in its constructor
and it just uses the super globals to set the class properites
I have not tried it yet but I assume the $_POST, $_SERVER etc do not exists when running a PHPUnit test?
I doubt it sends any HTTP Request headers
so to make this class more testable do you think it makes sense to pass in the $_POST, $_SERVER arrays in the constructor
so when I am instantiating an a request object I can define the data prior
 
okay, I understand your problem.
 
7:36 AM
sounds smart to me.
 
So yes, first of all you have to make those injectable - quite like you write, for example with the constructor.
That should also make the dependencies of the super global variables more visible and remove them from your request class. See this little tutorial:
5
Q: OOP how to show query

TredgedHere you go OOP :) class koffiepost { public function koffie($str){ if(isset($_POST['submit'])){ $haal = "SELECT * FROM koffie ORDER BY RAND() LIMIT 1"; $jij = mysqli_query($connect, $haal); $koffie = mysqli_fetch_assoc($jij); return $koffie[naam]...

You can then mock a request completely in testing.
Because testing runs in the CLI, $_SERVER is not defined.
And $_GET and $_POST are empty.
 
@hakre ok thanks. I inject all my other objects dependencies so I guess it makes sense to inject my requests dependencies
 
The other alternative would be to set $_GET and $_POST etc. however, as those are super-globals this is normally what you want to prevent.
 
yeah
 
@David exactly. Even strictly those are not objects, these are still dependencies.
 
7:41 AM
yeah I don't know why I treated them differently
 
@David Because by using superglobals in the past we're a bit trained lazy at that point (probably).
 
makes a hell of a lot of sense now I can configure my Request to have whatever data I want on construction
yeah I think it was lazyness
now it is clearer from the outside what my request class needs
what do you think about this. after I set the properties in my Request class I unset($_POST); unset($_REQUEST), unset($_GET)
 
that will be useful if you need to make cli scripts to interact with your framework as well..
 
can you unset superglobals
 
@David nope. just leave it alone.
every line of code you can spare, just spare.
 
7:44 AM
why do you say leave it alone? it will prevent me or anyone else getting lazy and doing $_
 
@David yes, but only by already doing it.
 
i suppose
@hakre i still need to learn about this mocking /stubbing thing
 
instead run your code in tests, as those elements are not set, you will get warnings anyway.
 
at the moment I have like 4 classes tested. I started with the one with no dependencies on other objects and if that passes and then use it in an object which needs it as a dependency. I am not sure if this is a good way or bad
 
@David If you can test everything you want it's okay.
You can however replace it with a stub / mock as well.
 
7:46 AM
yeah I am looking into that
 
but like you describe it, you don't need to.
 
how difficult is it
does it take a lot of learning
 
here are examples.
there are multiple ways to do it and those ways are different two.
 
this unit testing stuff is crazy
I have 28 tests so far
 
@David have you also looked into code-coverage?
 
7:49 AM
27 assertEquals. I don't need another other asserts yet. There is lots of them
no
whats that
 
When you execute your tests, a tool keeps records which lines of code have been exectued by which test.
So in the end you can see which code (roughly) your tests cover.
 
is it hard to implement
how do I get started with this
 
how are you invoking your tests? on the command-line?
if so, then it is as easy as using the --coverage-html switch, see phpunit.de/manual/3.8/en/code-coverage-analysis.html
if you're using a IDE, they normally support this, too and then visualize it in the editor after running the tests.
 
I run them from the command line
 
you can use that --coverage-html then, it will generate the report as HTML pages into a directory. You can then view it with your browser.
It visualizes it nicely, so you can get an impression how much lines you're testing already.
This can help to find out about dark places no light was brought into with your tests.
So you can think about why this isn't the case so far and you can think about if it's necessary or not etc.
It's some metric to review your tests.
 
7:56 AM
@hakre just ran it there and it said it saved the HTML file. can't wait to check it
 
Some folks aim for 100% code coverage, but take that with a grain of salt.
 
I am not going to test my Views I would say
 
Sure you want the perfect coverage of your code with tests, but by the tests, not only lines of code.
@David sounds sane :)
However you might want to test those files not containing syntax errors for example.
 
hi everyone
I just want to ask your idea that, do you use foreign keys inside your mysql database applications? Till now, I didn't use them and I always check the integrity operations in the app level. I have the theoretic knowledge, but didn't use them. Any idea, recommendation and advices are highly appreciated.
(for example I checked the db for pyrocms, it was all MyISAM and there was no foreign keys used, does this mean it is better not to use? )
 
@hakre this coverage thing is so easy but so helpful
@JamshidHashimi yes. some databases automatically index them too
 
8:02 AM
@David what is your recommendation regarding? please.
 
I have seen at work just 3 weeks ago a simple SQL JOIN with foreign keys and indexes takin off take something liek 43 minutes to complete at 99% CPU for the whole 43 mins and then with the foreign keys and indexes put back on it took if I remember correctly 9 seconds which was insane
taken off*
I would say use them
I don't see why not
except for in testing the constraints can be annoying when you want to delete a row or 2 but you can't because of the constraints
 
@JamshidHashimi If you use them, know what you get from it: Inserting takes a (little) longer (for the constraint checks) but you don't need to care in your app (that is what the database server is designed for, keep that in mind). Additionally querying is faster.
Old PHP applications most often don't use it because in the past it was not available. So those developers probably never thought about using it.
try both, make your own experiences. also read in the mysql manual about problems / shortcommings / useful notes about the feature.
14
Q: Why use Foreign Key constraints in MySQL?

OdelyaI was wondering, What will be my motivation to use constraint as foreign key in MySQL, as I am sure that I can rule the types that are added? Does it improve performance?

the accepted answer gives a very sane suggestion there IMHO.
 
@David woww, so much difference. Thank you..
@hakre thank you very much for these information. I now have a better idea to use them.
*
 
afternon
 
@hakre I did it. Thank you :)
 
8:14 AM
@Mr.Alien good afternoon mr. alien.
(albeit here it's a sunny morning) :D
 
@hakre lucky you, it's dark clouds here..
sigh even spoon feeding doesn't work
 
8:35 AM
 
@zerkms the earth is shaking?
 
@hakre A LOT
 
check twitter #eqnz to see it
short: no injures but some buildings damaged
 
@hakre I was just typing Earthquake :D
 
8:37 AM
If you won't see any activity in my profile tomorrow - just get a beer after me :-)
 
it will be a scary night
 
can you vote to delete a question before it's closed or before the 48hr wait period?
 
@crypticツ depends on whos "you"
 
@crypticツ if it's at -3 or lower (for us non-mods)
 
8:39 AM
I can delete old questions/answers without even a single negative vote, I don't know how
 
blah, ok didn't know that gotta tweak the code then
 
@zerkms the ring of fire. so you're living next to it I assume. good luck and be prepared.
 
@crypticツ are you using an IDE to write your code?
 
If anyones free, help this kid, gotta go for lunch....
 
8:44 AM
@Gordon yeah
 
@Mr.Alien some lessons need to be learned on ones own, you can't feed everything.
and have a nice lunch!
 
@crypticツ is there something in it to make it autoformat the code according to a coding standard? because your curly braces are not conforming to psr
 
@Gordon oh no, where am I not?
 
> Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.
@crypticツ everywhere. all your methods have them on the signature line
 
8:46 AM
@hakre than he will probably end up in a doubt loop ;) and thanks pal... have a great day ahead... cyo
 
@Gordon aack, you're right. I get confused since it's not consistant
 
@crypticツ and another nitpick: if the class is QuestionItem, the filename should be QuestionItem.php too
 
@Gordon kk, renaming
 
@crypticツ thanks
 
do you think it is a good idea to have my Session wrapper take an Array in its constructor of the session data? like $session = new Session($_SESSION) so I can then configure the session data easily during testing. does anyone do this
 
8:55 AM
@David yes. that's what you want to do with all the superglobals
 
@Gordon the thing is though if I accept an array of data and set it as a class property in the class and work with that, set new attributes, unsetting etc all that is only changing the class property not the session isn't it? or can I use a pointer to the memory address location of the $_SESSION
 
@David that would defeat the point. you want to get rid of the dependency on the superglobal
 
@Gordon but if i just pass in an array of data into my session wrapper and then I do $session->set('userId', $userId);
I have to set it to the $_SESSION right?
if i just assign it to a class property it will not exist when they go to a new page
 
@David no. you just have to make sure your php.net/SessionHandler can write your custom session
 
9:11 AM
ok
 
morning ....
 
^ looks like we failed to close this duplicate... .
 
@Gordon just looking at the session handler interface. so you are saying i should create a custom session handler and when the script finishes each time it will save some sort of $data array which is a class property of my session wrapper?
 
@David yes
 
9:24 AM
perfect
thanks
by the way
is that the only way to deal with sessions during unit testing?
being able to $session = new Session($arrayOfData);
 
@David the other way would be to move the session handling as far to the edges of your application as possible, e.g. just pull in the data in your bootstrap and (re-)initialize the various objects that make use of the data (not the session) with the data. and at the end of your script you collect that data to write it back to the session. that way you dont have the session stuff in most of your tests
 
ok
 
@David an alternative would be to use sebastian-bergmann.de/archives/…
but that's the default anyway
 
9:39 AM
grr. which php.ini does PHPStorm try to use? For some reason it apparently tries to take my PHP5.3 one
 
@Gordon depends on your run configuration.
maybe you have installed PHP 5.3 into c:\Programme\PHP\ ?
(or check PHPRC environment variable)
 
only phpstorm is using it. cli won't
 
It might not be phpstorm but just PHP choosing the ini. Specify which one to use in the PHP run settings instead. You can create multiple profiles per PHP version.
 
you cannot set which ini to use there
 
@Gordon okay, have you said in your project settings to use PHP 5.3?
 
9:42 AM
@hakre no. to 5.5
 
@Gordon use the -c switch, you can specify that with phpstorm.
I actually must have done something with php 5.4 because in CLI I used 5.3 for a longtime, but not in phpstorm
let me check
 
ah wait
I found whats wrong. its not phpstorm
 
mornign
 
@hakre apparently my pear.bat files use a wrong path
 
@crypticツ yay!
 
9:46 AM
@Gordon okay, that explains it. Because in PHPStorm you only specify the directory where the PHP binary is located and it never caused me such problems.
 
@PeeHaa I've been pushing commits all day =oD
 
@crypticツ Regarding your license question it depends a bit what you want. The not caring part is basically MIT (so at least others know what they can do with it), if you are concerned about the users of your software (not only other developers), you should take something like AGPL which comes with strong copyleft so users have a right to access the code.
 
@hakre eih, pear cannot upgrade the paths automatically?
 
@Gordon check if you have set PHPRC. Or PHPBIN in your environment.
AFAIK pear uses these.
 
@hakre MIT as long as I am not liable if someone's computer catches on fire.
 
9:51 AM
@hakre changed them .bat files manually now
 
@crypticツ Yes, MIT comes with this "WITHOUT WARRANTY" which is suggested for US and DE authors.
@Gordon I moved the PEAR directory IIRC.
So it was c:\Programme\PHP\Pear again
I have 5.4 in that directory, and there was 5.3 in it earlier.
Anyway, I have the fun again soon when migrating this box to Win7.
Albeit I know have put my Fedora box into dock since yesterday :)
 
I have PHP setup so that I can use my PEAR installation with any PHP version
the PHP folder is symlinked
 
@Gordon Yes, I have, too. But on windows PHP has this hard-encoded PEAR path inside it's include path.
It's only documented inside the php.ini comments AFAIK.
It's a bit surprising when you don't know.
 
@hakre the problem was that all the .bat files contained the old part before I symlinked
and apparently when you do a pear upgrade it won't recreate the .bat files
 
@Gordon ah, written out by gopear.bat probably.
 
9:54 AM
which you can indeed fix by setting the PHP_BIN_PEAR_WAHTEVA variable
 
yeah, it's all a bit of a mess. It sometimes hurts me in which desolate constitution the pear repo is.
reminds me that I need to fix a bug.
 
@crypticツ I noticed it. yay!
 

« first day (1009 days earlier)      last day (3954 days later) »