« first day (1955 days earlier)      last day (3215 days later) » 

21:01
Does anyone agree that PHP could use some syntactic sugar for making assertions about values (specifically, parameters) that could be of a number of types, but are all ultimately filterable to the desired type?
Like...
function gimme_characters($characters)
{
    switch (true) {
        case is_array($characters): $this->characters = $characters; break;
        case is_string($characters): $this->characters = str_split($characters); break;
        case $characters instanceof Iterator: $this->characters = iterator_to_array($characters); break;
        default: throw new InvalidArgumentException();
    }
}
The only reasonable alternative is to move the responsibility to the caller:
function gimme_characters(SpecificallyACharacterIterator $characters)
{
    $this->characters = $characters->getArray();
}
But then the calling code is mucked.
that switch is valid
@NorthbornDesign are you talking about matching pattern?
@JoeWatkins It is, but it's ugly as sin.
oh right, show me the sugary version ?
@FlorianMargaine Yea, just some construct to match types or structures... aside from switch (true), I think the required break is hideous.
@JoeWatkins Honestly? An expression-less, break-less switch wouldn't be terrible.
And maybe for uniformity, instanceof applicable to array, string, etc.
21:04
@NorthbornDesign also problematic is that the only case there that guarantees you an array of ~~~characters~~~ bytes is the string
someone had the idea to have a new switch syntax on reddit the other day, I tested the idea ... didn't look achievable actually ...
@NorthbornDesign s/break/return
it's not the nicest way to write that code either ...
function gimme_characters($chars)
{
    match {
        is_array($chars) | { $this->characters = $chars; }
        is_string($chars) | { $this->characters = str_split($chars); }
    }
}
welp, that's ugly
@NorthbornDesign ever heard of if/elseif?
21:05
@FlorianMargaine Perhaps.
switch {
    case $characters is array: $this->characters = $characters;
    case $characters is string: $this->characters = str_split($characters);
    case $characters is Iterator: $this->characters = iterator_to_array($characters);
    default: throw new ParameterException();
}
don't call me when you need a language designer
i never remember how to do the strikethrough :(
function gimme_characters($characters)
{
    switch (gettype($character)) {
        case 'array': $this->characters = $characters; break;
        case 'string': $this->characters = str_split($characters); break;

        case 'object':
			if ($characters instanceof Iterator) {
				$this->characters = iterator_to_array($characters);
				break;
			}

        default: throw new InvalidArgumentException();
    }
}
@bwoebi Yes, the cure for hideousness is more blocks.
what's wrong with that ?
21:06
@PaulCrovella surround with triple dashes
@PaulCrovella ---foo---
@JoeWatkins It just seems like a lot of code to accomplish something very common and straightforward for which a more succinct construct would be better.
@NorthbornDesign the question is, does your switch really make it more readable?
@bwoebi IMO yes, I'm guessing you say no?
There are reasons why you usually put goto labels and switch cases on their separate lines…
@NorthbornDesign I'm not sure.
Wes
Wes
21:09
@Wes :-)
Wes
Wes
so poetic. by @DragonBe on twitter
I can't really make it make sense in my head ...
oh I thought it was a cliff and it was getting ready to jump
switch {
    case $characters is array: $this->characters = $characters;
    case $characters is string: $this->characters = str_split($characters);
    case $characters is Iterator: $this->characters = iterator_to_array($characters);
    case $somethingUnrelated is happening: $this->characters = from($dragons);
    default: throw new ParameterException();
}
presumably that would be okay ... which seems really strange to me ...
21:10
@JoeWatkins what if it's an object implementing __toString()
@JoeWatkins Yes, but so is exit; echo "running";
requiring an explicit fallthrough opposite and instead of break would be dope
@Leigh the point was switch(true) isn't necessary, and was based off the original snippet ...
My whole point is, it seems that it'd be beneficial that we have a construct to perform type matching, and evaluate associated expressions, given the ongoing dynamic nature of PHP. Scalar type this and that notwithstanding, it's a dynamic language that still fails to unify iterable types under a common name.
> it's a dynamic language that still fails to unify iterable types under a common name.
well ... yeah ... but this is a problem all by itself ...
21:14
I'm okay with solving a problem with another problem.
I'm not sure we'll get there ...
Foreachable would be swell.
or if just everything was foreachable
that reminds me, still need to do that foreach/yield from string rfc
@JoeWatkins Hold your horses, lol
foreach (7 as $wut)
21:15
everything that isn't stupid ;)
@PaulCrovella yes ...
Perhaps anything passed to an Iterator could be silently wrapped as a sensible Generator?
@NorthbornDesign @PaulCrovella has a thing that would mean you could omit the whole thing ... I forgot about that ...
I think union types and foreach all the things is the nicest solution probably ...
convincing people there is something wrong with switch is gonna be hard ... coming up with a new sytax/control structure is gonna be shot down probably ...
you'd have to be stupid to argue that you shouldn't be able to foreach over a string, and yield from and foreach need to be consistent so we get that for free ... then you just need to hint for string|array|Traversable
I think there might be two union type rfcs being worked on ...
so the initial idea was for yield from - should I focus on foreach in the rfc and treat yield as a bonus?
@PaulCrovella I think so
@NorthbornDesign what are you using that array of characters for anyway? my list of use-cases for this thing so far is just a streaming parser, and I'd like to expand that if possible
21:26
Hello
maybe we could RFC interfaces for magic ... don't see another nice solution to the __toString problem, and if interfaces land in core we can polyfill them after the fact ... @Leigh ?
Do I need to scroll up and read the original problem? :x
say in the future
we have unions, so you can hint for string|array|Traversable
still can't cover __toString
or
That is true
union types could be a bit magical
if you hint for Traversable|array|string, it could cast to the leftmost type that the variable is able to support, by whatever means we can detect at runtime ...
magic is magic ...
21:30
string|array|Traversable|::__toString \o/
Wes
Wes
void rofl(Object object){
String baz = object.toString();
}
Quick question … a string typehint … is the object casted or not? (currently I mean)
Wes
Wes
we could have Stringable or something
I've not actually used weak mode, so not sure
Stringlike
be sure to let them know you're giving them enough to hang themselves with, of course
21:32
Are these two conditions identical ?
@bwoebi no !
IF (col IS NOT NULL AND col > 0) THEN
IF (col > 0) THEN
that would seem like reasonable behaviour I think
shall we fix it ?
@JoeWatkins by removing __toString()? yes, please.
oh sorry, it is
its cast
so then when we have unions presumably it would magically cast in weak mode anyway
but what about strict mode (the one we actually care about now) ?
21:34
we should have interfaces instead of magic
yeah I think interfaces are probably nicest ...
or if they can't get in
Interfaces allowing casts are still magic
5 mins ago, by Leigh
string|array|Traversable|::__toString \o/
this isn't horrible I don't think ...
Wes
Wes
i wouldn't have anything magic
public function baz(Stringable $foo){
     $foo = (String)$foo;
     // there you have a string
}
this is ok
but the point was we are hinting for a traversable thing
so you don't want to cast an array to a string, or anything else, because surprises
so there isn't really a nice way to write the code, even if we have an interface ... is there ?
you're still going to end up with at least one branch
Wes
Wes
21:37
it's a mess
so the ::__toString syntax looks appealing, because special, so we can apply special meaning to it and no surprises ...
and you're still fucked if someone throws in a bucket of User objects as the iterator
@PaulCrovella That was actually a contrived example. My biggest use-case is unified array/Iterator. Given a userland collections class (or perhaps something eventually in core) It'd be nice to pass $col->map('someMapper')->filter('someFilter') directly to an array parameter.
Or vice versa.
Wes
Wes
21:40
related: how about deprecating traversability on all objects?
class Foo{ public $bar = 10; public $baz = 20; }
foreach(new Foo as $v){}
@Wes very funny ...
Wes
Wes
is there people that do that, without implementing Iterator/IAggregate?
@Wes why? It's actually useful for some stuff like serializing...
internal classes don't need to implement those ...
Wes
Wes
@Danack on public props?
y u even use public props :B
21:43
regardless, it would break too much code in the wild ...
Yeah, for value objects, public all the things.
there might not be any good code that relies on it, but code in abundance there will be because 20 years is a long time ...
/just don't 'accidentally' mutate objects.
Very short question, I am trying to fetch data from my database: 1. User submits form which activates my php script. 2. He gets automatically redirected to myphpScript.php (i didn't chose that, this is the way php works) and my script fetches data from the database. What I would like: that the fetches data gets printed on the first page containing the form the user submitted. Because now I can redirect the user to the page of the script using header(
@Danack did you see the evil value objects patch ?
21:45
nope.
*the form
Using header()
<?php
interface Foo {
        public function method();
}

struct Bar {
        public function method() {
                return 1;
        }
}

struct Qux extends Bar implements Foo {
        public $member = 1;

        public function method() {
                return 2;
        }
}

$qux = new Qux();

function mine(Qux $qux) {
        $qux->member++;

        var_dump($qux, $qux->method());
}

mine($qux);

var_dump($qux);

$reflector = new ReflectionClass(Qux::class);

var_dump($reflector->isStruct());
> mail the "internals" mail list to judge interest before you start your RFC
How can I avoid being redirected to my script.php? Or eventually pass all the fetches data trough the pages?
/me shudders
21:48
Anyone?
!!version
@PaulCrovella do that with the draft, to avoid discussion going in pointless directions ...
@PaulCrovella In the interest of full disclosure, I don't think it will be accepted
I remember it having been discussed before
@privetDruzia I have no idea what you're asking. "How can I avoid being redirected to my script.php?" - just don't set the redirect header?
21:49
The outcome was that trying to foreach over a string is more likely a bug than intentional
of course it is. right now. because it's not a thing that works.
@PaulCrovella Under assumption of it working, obviously ^^
@Danack:
Very short question, I am trying to fetch data from my database: 1. User submits form which activates my php script. 2. He gets automatically redirected to myphpScript.php (i didn't chose that, this is the way php works) and my script fetches data from the database. What I would like: that the fetches data gets printed on the first page containing the form the user submitted. Because now I can redirect the user to the page of the form using header(), but then all the data is lost
Acrobat Reader crashes all the time :/
in any case I'm fully prepared for it to be shot down
So I d eventually want that the php script without automatically redirecting me to myphpscripr.php, so I just stay on the same page
Find the bit of code that is doing the redirect, and remove it?
@PeeHaa that page doesn't look very trustworthy
But that's what I already wrote twice!
It doesn't, but it's a very nice pdf reader
As in "it just opens pdf files"
21:54
When you submit a form in html like <form action="myphpscript">... Once you press the submit button you automatically get redirected to myphpscript.php
And I don't want this to happen!
priviet are you talking about form action=""
@PaulCrovella :)
I want my php script to get executes without redirecting me
just erase action=""
21:55
that's a good attitude to have ... it probably will be ... try to tackle every argument against it ... why isn't it a bug ??
@Jarzon BBut then my php script will not be executed!
my current quandary is whether it (or anything) is worth dealing with internals over
I'm gonna let the pot head speak for a minute ... things can only stress them out if you let them, man ...
you want to exec the code of "myphpscript.php" but stay on your form page?
I develop on my machine before pushing to the production box, both of which are using WampServer (shame I know), but this is the first time where it didn't work when I moved the code. Looking at the PHP error log was my first guess and it points me to some code that should work, not sure why it wouldn't, especially when it works on my machine.
21:59
Yeeees! Jeez
get the code of myphpScript.php
Christ...
@PaulCrovella I recommend dumping a mail on internals and then ignoring the thread. After a few days come back and maybe write one response
yeah, don't get all amongst it and try to respond to every little criticism
^^ this. Possibly just ask in here if there's anything that needs responding to.
22:00
@Jarzon Get the code and then what?
considered, careful responses are the order of the day ...
Do you know you can have php and Html in the same page?
No
Except includes...
Yea about that
does myphpScript.php output anything?
How do you keep development/production boxes in sync in terms of settings/versions etc?
Wes
Wes
22:03
@JoeWatkins objects could be all made Traversable<mixed, mixed> (not that Traversable should be generic) and so would be arrays and strings, so you'd have:
function baz(Traversable $stuff){
     Traversable $stuff = $stuff instanceof Stringable ? (String)$stuff : $stuff;
     // ...
}
Yes it does output fetched arrays from my dbs
Wes
Wes
if it's not Traversable, then another new super interface, like "Iterable"
@Wes I think you mean ReallyTraversable
Wes
Wes
ActuallyTraversable
22:05
@ja
@Jarzon, so?
Wes
Wes
yeah so strange that arrays are not Traversable. i will never understand php :P
You want to have the php code of myphpScript.php in your form page
I've had enough of today, nite all
the issue is that it should fetch the data and tgen refresh the page so it can echo the data
have to be like myForm.php
22:08
I think it might not wok without refreshing the page (unlike javascript)
nevermind, wrong fraction
Doesn't have to refresh the page
You can print it in html
Wes
Wes
btw, about "generalize-support-of-negative-string-offsets"'s "future scope"... i'd have $str[0] returning integers at some point, like in php 35.0
like <input value="<?=$result['value'] ?>">
What you want is to submit the data of the form without losing them?
22:11
Ok i ll try that
I m on my cellphone now, so ....
hello guys
sup
So chat on cellphone is really crappy....
22:12
<span class="text-center"><i class="glyphicon glyphicon-earphone fa-sm"></i></span>
why fa-sm doesnt work ?
bootstrap library
what i need to include ?
No the user sets specific options in the form. With those options i ll know which records i ll need to retrieve from the dbms and just echo the
Like ebay s search engine
@Jarzon ^
But how do i specify that my php code should be exec when the search btn is clicked if yhere s no "action"
?
@Jarzon
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
Solved
posted on February 22, 2016 by bwoebi

amphp/amp v1.0.8

22:35
^ Bugs causing 100% CPU usage <3
lazy-ass cpu wasn't doing anything better anyway
Haha
@PaulCrovella need to revert that then :-P
Wes
Wes
damn kids again with drones spying into houses
stupid 21st century...
22:51
didn't get sling?
Wes
Wes
will buy tomorrow. not joking xD
why is everything harder on Linux?
Wes
Wes
viagra overdose maybe?
if linux persists for more than 4 hours consult your doctor
I'm trying to remove php5 and switch to php7... I've built and installed 7, getting apache to play nicely with it is the issue
22:56
use .php7 files
Wes
Wes
verbs for getters: yea or nay? like, getCount() vs count()
count can be noun... getCount()
Wes
Wes
actually, also nouns. yes
@FlorianMargaine I don't understand
Wes
Wes
i believe he was joking
23:01
@iroegbu 'twas a joke
ha! I've been murking around apache config looking for php7 as a module.
@Wes yeah makes it clear that it returns something
Wes
Wes
23:25
it's tough because for some things getTers are weird. like some booleans ($foo->contains($baz)) but not all of them ($foo->setVisible(true), $foo->isVisible())
aren't there guidelines or something?
when it gets weird do something else
or get freaky with it, if that's your jam
it's probably about what the state stands for...
Okay, I've figured out my php problem... I built it with Nginx in mind so no --with-apxs2
Wes
Wes
i'd say, if it's a function then it must be prepended with a verb, like is, get, has, contains, set etc. like, $foo->visible() sucks, should be isVisible()
I agree, was referring to how the verb is picked...
"must" is a strong word. there are cases where the verb is implied and it's still perfectly clear, e.g. with* methods of immutables
Wes
Wes
23:37
that is just FIG. who cares of that :B
23:52
if it's clear it's clear, I don't care who wrote it or what part of speech it is
Wes
Wes
it's not clear at all, imho
also it's a stupid design in my opinion. should be $mutable = $immutable->edit(); $mutable->setStuff($stuff); $immutable = $mutable->freeze();
but i get your point though. idk. naming is hard as usual

« first day (1955 days earlier)      last day (3215 days later) »