« first day (1725 days earlier)      last day (3223 days later) » 

12:01 AM
As per the discussion on internals - if it starts off as Exception, it isn't a problem to make it more specific. If it starts off as a specific exception, changing it is hard....
 
yeah
changing it to a new exception is fine
changing to an existing exception may be problematic
 
Do I need to create a new RngException or can I just throw an Exception?
 
12:28 AM
@SammyK I would throw Exception for now. you can always make it more specific in a later moment
but most importantly, is it an Exception or an Error? can one actually recover from that?
 
@RonaldUlyssesSwanson It's recoverable so another CSPRNG could be used.
 
how would the exception be handled, for example?
 
```php
Doh!
Lol
 
@SammyK I suspect we need a generic SecurityException to be used whenever there is a problem with any condition that might affect security.
 
12:35 AM
try {
    $bytes = random_bytes(42);
} catch (Exception $e) {
    $bytes = openssl_random_pseudo_bytes(42, $cryptoStrong);
}
 
four spaces or press ctrl+k
 
@Danack Thanks for the tip! :)
 
@SammyK can openssl_random_pseudo_bytes fail too?
@Danack could be, as in GeneralSecurityException in java
which is the base class for every security exception (iirc)
 
Sometimes for the *CS* part of the *CSPRNG*. [From the docs](http://php.net/openssl_random_pseudo_bytes):

> It's rare for this to be FALSE, but some systems may be broken or old.
 
user4268046
Is there way to append the values of two arrays together?
 
user4268046
12:43 AM
so array("moo" => "x") + array("moo" => "z") would return array("x", "z").
the keys are irrelevant.
 
@SammyK Exception or SecurityException would be fine
 
@TheMineBench You can make use of array_values() and array_merge()
 
user4268046
@SammyK Thanks ^_^
 
Np!
 
@TheMineBench or even $array3 = $array1 + $array2; (note that behaves differently from array_merge)
 
user4268046
12:58 AM
@RonaldUlyssesSwanson How so?
 
user4268046
array("moo" => "x") + array("moo" => "z");
returns array([moo] => x)
 
user4268046
@RonaldUlyssesSwanson Ah I see, yeah array_merge is what I want. Thank you :)
 
user4268046
There doesn't happen to be a array_diff for RecursiveIteratorIterator?
 
spl is madness @TheMineBench
 
1:45 AM
Chat, no other way to get fully qualified local machine hostname in php other than to exec hostname -f?
 
2:26 AM
Hmm... a PSR for standard exceptions: groups.google.com/forum/#!topic/php-fig/8eV_evK7ZRI
 
need help to show result like below

[
{
code: "AF",
total: 1
},
{
code: "DZ",
total: 1
},
{
code: "AS",
total: 2
}
]

to
{
"AF":1
"DZ": 1,
"AS": 2
}
how can i do that in php ?
as i am getting the data from database
$arr = array();
	#If no data was returned, check for any SQL errors
	if ($res == false)
	{
	   echo 'Query not Executed : '.  die(print_r(sqlsrv_errors(), TRUE));
	}
	else
	{
  		while($obj = sqlsrv_fetch_array($res, SQLSRV_FETCH_ASSOC))
  		{
  			$arr[] = array(
  				array_search($obj['name'], $countries_iso) => $obj['Total']
  				);
  		}
	}

    header("Content-type: application/json");
	#Output the JSON data
    print_r(json_encode($arr));
this is my current code
???
@Trowski ???
anybody here ???
 
user4268046
2:48 AM
Is there something in php that is similar to String... in java?
 
yes
PHP
 
@TheMineBench Sure, a string.
 
user4268046
"String..." in java allows you to call a method like method(arg1, arg2, arg3...)
 
@TheMineBench Yes, but scalars don't have methods in PHP. However, strings are simply byte arrays in PHP.
You do have the non-standard PECL library SPLString if you really wanna go that route php.net/manual/en/class.splstring.php
 
@TheMineBench but how i can pass the argument to
array_column($records, 'first_name');

as they have fixed Like (first_name) but in my case everything is different
 
2:53 AM
Though good luck extending it...
@Mediasoft What have you tried?
You can't fail if you don't try and you can't learn if you don't fail :)
 
@Sherif asking in the js room :P
 
@rlemon Sounds like impermeable tribulation :D
@Mediasoft The way to learn to is to start somewhere. 3v4l.org/RJ7aC It's not perfect, yet, but it has given you the desired result. Now the trick is to go back, read the documentation again, and gain some deeper insight in order to wield the tool more skillfully. Later comes abstraction and generalization, 3v4l.org/FHn4H, which requires resurfacing that earlier acquired knowledge and applying a little bit of logic and a touch of imagination..
 
3:13 AM
hey
how to anchor links in horizontal scroll?
<a href="domain.com/#anchor">
not working on horizontal
 
Wait, wat?
This is still room 11, no?
 
@Sherif maybe, maybe not.
 
The metamorphosis is happening. Not sure if it's still room 11 now.
 
 
1 hour later…
4:22 AM
function makezip() {

$zip = new ZipArchive();

$DelFilePath= __DIR__ ."/my.zip";

$urls = $_POST['urls'];

if(file_exists($DelFilePath)) {

unlink ($DelFilePath);

}
if ($zip->open($DelFilePath, ZIPARCHIVE::CREATE) != TRUE) {
die ("Could not open archive");
}

foreach ($urls as $path) {
if (!file_exists($path)) { die($path.' does not exist'); }
if (!is_readable($path)) { die($path.' not readable'); }
$zip->addFile($path);
}



// close and save archive

$zip->close();
echo $zip->getStatusString();
What's wrong with this code? I don't see any errors but I don't see a zip file in my directory either
 
how we can hide the API Link from Browser Console ?
 
@Trowski they are so ugly
 
5:00 AM
Hi everyone! MY very first visit to PHP room.
 
What is PHP?
This is the Scala room.
 
@Sherif Then am i in the wrong house?
 
good morning guys...I'm trying to create a desktop application using nightrain..I copied my files in www folder ...when i execute the exe file php info window is opening up...My question is how to execute my application?
 
@user12688 have you read this at least?
 
@RonaldUlyssesSwanson I know... and it's like they're seriously considering it.
 
5:11 AM
hello
pg_prepare($this->dbConn, "my_query", 'SELECT * FROM "user" WHERE username ilike %xyz%');
$result = pg_execute($this->dbConn, "my_query");
any one tell me this query is prepare or not means this is valid or not
 
@SergeyTelshevsky ok let me try...
 
There's just no way to cover every possible scenario in a single PSR. Each PSR could have specific exception types, but that's too much.
 
class InvalidValueException extends \RangeException
i like how validation is considered different to... whatever it's not validation :P
 
hi i'm revisiting codeginiter for the first time after some 3yrs! i'm searching for very light weight framework as i want my website to be extremely fast! I'm considering YII and laravel as alternatives. any suggestions?
 
5:19 AM
@krishna yii and laravel are just as bad
best suggestion is, don't use a framework (or make your own)
 
@RonaldUlyssesSwanson i've been using cakephp from 3yrs! If i've to make a choice among existing frameworks, what shall be my choice?
 
no idea, honestly
 
@RonaldUlyssesSwanson That's quite possibly the worst suggestion you could offer anyone
 
@Sherif why. even if they get it wrong, at least they would know why
what's so bad with just using plain php? i don't know..
 
@krishna Don't choose the framework based on speed. Choose one that helps you build something that you can maintain. Speed is of little concern for an MVP. You can always figure out ways to make it faster. First you have to figure out if it's worth your time.
 
5:29 AM
@Sherif its broad answer! I've experience in building websites with Cakephp but i observed its little heavy, so am considering alternatives
 
@RonaldUlyssesSwanson Because human time is much more expensive than computer time. In a world where technology moves at such a rapid pace you simply don't have time to learn everything from scratch. You should learn to use your time wisely. Focus on the things you're good at so that you can win where you're already winning.
 
and mornin
 
@krishna Great, just don't consider those alternatives based on speed, because honestly the speed of a PHP framework plays such a small role in the overall speed of your website that really doesn't even matter.
 
@Sherif till you realize that the whole industry moved on and you are still stick with vb6 [true story]
 
In an age where computers are so fast, do you really care?
@RonaldUlyssesSwanson Because with your suggestion the industry is going to stop and wait for you to learn how to build your own framework first?
 
5:32 AM
you don't need one
 
Moving fast is about getting something to work well, for just a few people first and then you can figure out how to make it work better and faster for millions of people. The truth is people may not like what you made and so you will have wasted all that time focusing on things that ended up not even mattering.
 
just use raw php
... and spare tools
not a whole framework
 
You may not, but there certainly is a lot of good code out there that can spare you from reinventing the wheel.
 
iirc this room once collected a list of tools for to "build a php site without a framework"
 
@Sherif i agree
 
5:33 AM
can't remember the url
 
What is a framework if not a collection of libraries and tools that make developing easier?
 
Blanket statements are almost always destructive in nature. Don't choose to be destructive. Instead, consider building on top of what's already out there and make it work for you.
That's much easier than trying to be seclusive.
If you think about it, PHP itself is a framework.
At it's core it's nothing more than a parser with a very rudimentary runtime. It's usefulness stems from the collection of extensions that tie into and extend that runtime from a bunch of third party libraries.
The framework is just another higher level abstraction on top of that.
 
So try not to make it more derogatory than it really is. Instead, if you have some beef with some particular part of a framework, let that grievance specifically be known, and offer them an alternative.
No need to make such blanket statements.
 
5:40 AM
the thing is, i can't trust php frameworks. i could and maybe would use one, if there were good ones, but that's not the case. it's as constant as speed of light. therefore, i can't recommend frameworks to anyone
 
That doesn't mean recommend that everyone build their own framework either.
 
> reinventing the wheel is a very important task to do if you want to learn more about wheels
 
But not if you want to get shit done
Not everyone writes code purely for academic purposes.
 
at least they would get full control (ish) of what they are doing
 
control is an illusion
 
5:43 AM
@Sherif one can build a framework by getting shit done
even over a 10 years period
 
If you spend all your time building the perfect framework, all you've done is build the perfect framework. Doesn't leave you much time to work on the actual application.
 
it would still be better than any php framework
you don't need a perfect framework
only spare tools
 
Great, but in the mean time some of us need to get something up and running within the near future. Not in 10 years.
 
that you can exchange with others or improved ones at any time
 
@RonaldUlyssesSwanson All more the reason to use the already existing imperfect ones then ;)
 
5:45 AM
@RonaldUlyssesSwanson /me coughs BOOKS
also morning
 
morning
brb shower late
 
@JoeWatkins 6d6f726e696e67
 
@Sherif 6d6f726e696e6720736865726966
 
3a29
 
it felt like it took an hour to work that out
I have to spend the day eating lots of dinners, won't be able to eat for the next few days, dental work being done tomorrow ...
gonna start with maccy d's I think for breakfast ...
 
5:54 AM
You can't eat for several days?
 
having wisdom teeth removed, and a couple of others, I'm told no solids for at least 48 hours ... after 48 hours it's just a question of whether I can bare the pain ...
 
oh yeah, that's painful
 
so I can have yoghurt or soup or something, but if it didn't have a face at some point, its not a meal imo
 
pg_prepare($this->dbConn, "my_query", "SELECT * FROM 'user' WHERE username ilike 'xyz'");
$result = pg_execute($this->dbConn, "my_query");

(OR)

pg_prepare($this->dbConn, "my_query", 'SELECT * FROM "user" WHERE username ilike $1');
$result = pg_execute($this->dbConn, "my_query", array('xyz'));
 
I just remember being on a lot of drugs the whole time :)
 
5:56 AM
Both query are running properly but i want to know which is correct for prepare statement?
 
they are doing it under sedation, which wears off completely in 24 hours, but I don't think they are giving me anything more substantial than something codine derived to take home ...
 
They're both correct.
 
anyone?
 
are they really @Sherif ?? what happens to that array, pg converts to string ?
that'd be kinda strange imo
 
@JoeWatkins Where's that?
There's no array to string conversion there.
 
5:59 AM
$result = pg_execute($this->dbConn, "my_query", array('xyz'));
 
There's no array to string conversion there.
 
so what happens, I'm genuinely asking a question ?
 
It executes the statement?
 
i dont know
 
oh sorry
 
6:00 AM
both working
 
it's param array, gotcha ...
 
:)
@KajalSingh Both are technically correct, as you have already and obviously derived by running the code. I guess what you really meant to ask was "What is a prepared statement and how do I use it?"
Because clearly if you have to ask that question you don't understand the purpose of a prepared statement.
Think of prepared statements like you would HTML templates for your SQL. You prepare the template once, and inject the place holder values (your parameters), each time you wish to execute the statement.
All you did on that first example was create a static HTML page with the values already embeded.
So there was no point in using a prepared statement obviously. You just wasted a round trip to the server.
And on a totally random note: this is just pure gold platinum rescomp.stanford.edu/~cheshire/rants/Latency.html
 
I want to know first query is preparing or not because pg_prepare() is also use with statement. If both query are executing through prepare statement then which is correct query?

Is prepare statement can be used with SELECT statement without any clause like
SELECT * from tbl_name
 
@SergeyTelshevsky what after php info window...i'm confused with this thing...how to run my app in this....every tutorial is showing upto php info()
 
@KajalSingh It can, but like I said, what's the point? You've just wasted an additional round trip for nothing.
 
6:12 AM
@user12688 please, read the link once again.
there is clearly written what you should do
 
Reading is hard stuffs :/
 
no rocket science there
and not a wall of text too
 
@Sherif its showing windows output with php info image...
 
@user12688 OK
 
@Sherif reading is not a hard stuff...understanding it is a hard stuff
 
6:14 AM
It's a good thing you're looking at the pictures then.
 
thats all
 
@Sherif Is first query preventing sql injection?
 
@KajalSingh The first query isn't susceptible to any SQL injection.
Where would you inject the SQL there?
 
@Sherif Data 'xyz' is coming from input form
 
@KajalSingh No it's not. It's a literal string.
 
6:19 AM
pg_prepare($this->dbConn, "my_query", "SELECT * FROM 'user' WHERE username ilike $cc");
$result = pg_execute($this->dbConn, "my_query");

What about that?
 
Sure, that is clearly vulnerable to SQL injection.
At least as far as we can tell.
Who knows wtf you're doing with $cc
Keep showing us more random snippets of code and asking us which ones are vulnerable to SQL injection. It's much more worthwhile than learning what SQL injection is or how a prepared statement works or how to use it.
 
@Sherif sorry for this
 
@KajalSingh No you're not.
You already knew the answer all along.
 
6:35 AM
holy mother of god intlchar has just too many constants @JoeWatkins :P
i wish you could have used enums for that
 
6:55 AM
I didn't do intlchar
blame @Sara
/me hides
 
lol :P there is no other way to do that currently
and god icu's naming consistency is awful
@Sara have you considered fixing the names a bit?
iscntrl($codepoint) -> isControl($codepoint)
isISOControl($codepoint)
 
7:15 AM
morngon
 
mohaa
 
mohin
 
Holy crap. When Java crashes it really fucking crashes
At least when PHP crashes the worst that happens is you lose that one request in time, but I mean this thing just crashed my entire system. It took down the IDE, the browser, the fucking JVM.
I destroyed the whole castle with one thread. Awesomesauce!
 
lol
reminds me of chrome. when firefox crashes, and it does that often, you just get it closed or you will have to close it. instead, when chrome crashes you get your whole system unstable
 
7:30 AM
meh, who needs thread safety really. If you can't operate in a single thread you're not hardcore enough.
 
#nodejs4lyfe
 
one thread to rule them all
 
libGL error: Try again with LIBGL_DEBUG=verbose for more details.
God damn it!
Stupid useless error logs with all their stupid lack of verbosity!
Why you no verbose enough?!?!
 
morning!
 
7:42 AM
@JoeWatkins is there a way to set the unicode version in intl stuff? i was thinking about inconsistencies between different php exts. for example, what unicode version does pcre use?
unicode version should be the same on such extensions imho
 
unsure
 
can someone tell me, if you use w or s keys in chrome it scrolls the page, then when you hit the top or the bottom it may switch the page to the next one. how is it called? I know it's not new, it's been in opera for a while, but how do you control this from a web developer point?
 
@SergeyTelshevsky ?
 
@RonaldUlyssesSwanson what exactly do you want to say by '?'?
 
@SergeyTelshevsky it doesn't do anything when I use w or s in my chrome
 
7:49 AM
@SergeyTelshevsky more details about your question? what is "next one" ? the next tab?
 
oh shi*. it was a js script on that page, not chrome :(
but opera had similar functionality of detecting (most likely by digits in url), like if you're on http://www.com/page/1 and press 'forward', it went to http://www.com/page/2
it was implemented in some pre-webkit opera's
 
never heard of that, sorry
 
It's HTML, not browser-specific.
Opera just does greedy caching.
 
@SergeyTelshevsky you want to implement it yourself? "how do you control this from a web developer point?"
 
> You can use the HTML attributes rel="next" and rel="prev" to indicate the relationship between individual URLs. Using these attributes is a strong hint to Google that you want us to treat these pages as a logical sequence.
 
Anonymous
7:55 AM
Morning o/
 
yes, or with microdata/microformats pagination stuff
 
@SergeyTelshevsky Some client UA implemntations like Opera just pre-fetch these urls for you.
 
nice, looks like that's one of the ways opera detected this, but I doubt many websites used these tags..
 
@SergeyTelshevsky many do. For example, CMS handle paginations and usually do that.
 
@SergeyTelshevsky Only the ones that know how to use HTML
which is about 1% of the web, basically
 
7:58 AM
you'd be surprised.
 
@SergeyTelshevsky you would be surprised
@FlorianMargaine lol
 
I'm rarely surprised. I've seen things. Things few men should ever have to see.
 
@Sherif I think wordpress does it on its own, so you already have 24% of websites doing it
 
:/
 
drupal does it too, so add in another 2%
etc.
 
8:01 AM
@FlorianMargaine Yea, wordpress is not 24% of the web my friend.
> As of Janaury 2014 there are around 861,379,000 registered host names
 
LOL
 
even if not 24%, it's far more than your "1%"
 
@JoeWatkins how do i see which unicode version is used by pcre? iconv and mbstring too
 
60.2% of the web?
Really?
 
8:02 AM
> of all the websites whose content management system we know.
read the thing
 
@FlorianMargaine 24% of the web would be ~206 Million hosts. So, good luck with that.
99% of all statistics are made up 100% of the time.
 
oh, now that you have no source, you're just playing stupid. Oh well...
I should just ignore you.
 
^
 
@Sherif oh yes, 18% is much closer to 1% than 24%.
 
8:07 AM
@Sherif lolled at this :D
 
@FlorianMargaine Like I said, 99% of all statistics are made up on the spot 100% of the time ;)
 
or you can't admit you're wrong
 
It's not as though they show you how they arrived at 18.9% other than stating the number of times it was downloaded.
 
So, how does one ignore a user on mobile...
 
@FlorianMargaine Certainly I can. Can you?
:)
 
8:10 AM
@RonaldUlyssesSwanson you could try documentation, but it might be wrong, read source I would
 
stop it guys. we are not kids
@JoeWatkins i wish i know how xD trying...
 
lxr ftw
look at config.m4 for each thing, see what it links, search for appropriate initialization call for whatever lib is being used and you should have your answer ...
 
Such salient cynosure circuitously seeking surreptitious cessation.
An assuasive alliteration wafting ardently wherein!
^^
 
> See the comments about C/POSIX character classification functions in the documentation at the top of this header file
clearly, there are no such comments
 
8:26 AM
Hello, $_SERVER['HTTP_USER_AGENT'] does not return the right information for Opera , is this a known behavior ?
 
what you want to do with the user agent string?
 
@Joseph What information does it return?
 
@Sherif this : Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.125 Safari/537.36 OPR/30.0.1835.88
 
@Joseph Seems right to me.
 
should it not be returning information only concerning OPERA ?
 
i want to use it to define which browser i am using
 
HTTP_USER_AGENT is user-supplied data. It is provided by the client. That is what your client UA is providing to PHP.
 
it works fine for IE , FF AND Chrome
oh ok, so i need to modify my browser's settings ?*
 
The UA string doesn't always contain the explicit brand name of the browser. In many cases it provides generic information pertaining to the UA implementation.
 
I read this somewhere : "in opera you get an option on how you wish the server to detect it: either IE, Opera, Firexof (press F12->site preferences) "
 
8:35 AM
Like the fact that it's running WebKit ^^
@Joseph Yea, pretty in any user agent you can specify or even hide the UA string sent to the server in the HTTP request. Like I said, it's entirely user-supplied data.
 
So trying to detect which browser you are using is not 100 % guaranteed ?
 
The UA client isn't required to supply it at alll.
@Joseph Correct.
 
alright :)
 
Though there is something called brwosercap.ini, which I'm sure you can Google and learn some more about.
It tries to decipher from the UA string which browser software the client is using.
Assuming the information supplied was accurate.
 
use Regular Expression to check if it's Opera like this way:
if(preg_match('/Opera/i', $_SERVER['HTTP_USER_AGENT']))
{
// this is opera
}
 
8:37 AM
@MuhammadSumonMollaSelim Did you not notice when he provided the UA string he got from $_SERVER['HTTP_USER_AGENT'] didn't contain the word Opera?
heh, that was his entire point of asking the question.
 
@MuhammadSumonMollaSelim that's what i use, it doesn't work for the reason mentioned by @Sherif
:)
I am using the example given by ruudrp at live dot nl ¶
The first one
 
if you need to sniff the ua string, you are doing something wrong
 
The only way this would work is by changing the Opera preferences :)
i am doing nothing wrong, i guess ..
 
why do you need to know which ua is being used?
 
8:44 AM
It's fine for analytical purposes. It's just rarely reliable.
 
@RonaldUlyssesSwanson I've done that occasionally when being hit by a really specific bug for which there was no real solution
As long as you understand the limitions it's ok imo
 
@RonaldUlyssesSwanson Many websites look for mobile UA hints in the UA string in order to prompt you to download their mobile app, for example.
 
mostly for IE bugs, amirite?
 
Or offer you an option to redirect to their mobile site version
 
@PeeHaa no, no, no, no, no, no, NO
 
8:46 AM
i.e. IE8 having weird rules w.r.t. 301 urls or something... was it relative not working, or absolute? I don't remember. Or iframes not loading their js if they're hidden... weird stuff. IE is very buggy.
 
@RonaldUlyssesSwanson :P
 
Generally you don't care what browser, specifically, someone is using based on their UA. Just sometimes you want to detect certain capabilities indicated by the UA, like if it's a mobile device, or is Mozilla compatible, etc...
 
@FlorianMargaine Or old android stock browser.
God what is that a fucked up browser
 
But yea, that ends up translating to a lot of people using it to detect IE bugs ;)
 
@PeeHaa heh
@PeeHaa did you know that CORS is supported on old android stock browser, but you need additional CORS headers for that?
 
8:48 AM
yes, mainly using it to detect IE. For compatibility reasons
 
And the shocker is I see so much traffic from IE8 and even IE7 and IE6 still out there. It's abhorrent!
 
I learned about a lot of tricks, like about:debug
thank god there were some debugging tools
 
All those companies that can't afford to upgrade their licenses keeping their employees on ancient browsers.
 
moin
 
8:51 AM
@RonaldUlyssesSwanson ... there's no PC?
 
@FlorianMargaine I actually didn't no? Access-Control-Allow-Origin-Specially-For-Retard-Browsers: potato?
 
no 20"+ screen?
@PeeHaa pretty much, yes
 
@DaveRandom o/
@Sherif On sites you work on?
 
@PeeHaa On sites visited by hundreds of millions of people, yes.
 
8:53 AM
lol glad I don't have that problem
 
Most of them come from China and India
 
Luckily people in my business care more about mobile support than old browsers
 
I don't know if that speaks to piracy, or just outright lack of upgrading
 
@Sherif Ah yes. I don't have to tell much with that continent
@Sherif The first (at least for china)
 
Well, with mobile traffic surging, we're definitely bound to see less and less of IE
hopefully
 
@Jay wtf. drugs are bad m'kay
 
> Please help me to create html5 man typing in computer effect , I'm afraid to develop in to coding have design ideas
 
Anonymous
xD
 
8:56 AM
@Jay Wow, the quality of questions has certainly dropped a notch or two on SO since I started coming here.
 

« first day (1725 days earlier)      last day (3223 days later) »